изменить фон прогрессиалог и алертилдиалог в андроиде?

1

В моем приложении есть диалог alertdialog и progress. я хочу, чтобы мой диалог прогресса и диалоговое окно предупреждения выглядели так же, как и в iPhone. как я могу изменить фон обоих из них, чтобы достичь этого?

Изменить: Также я могу достичь этого эффекта, используя пользовательский вид? Что-то, что расширяет класс диалога прогресса.....? благодарю вас за помощь.

Теги:
progressdialog
alertdialog

2 ответа

1
Лучший ответ

Отметьте этот ответ: Как изменить фон диалоговых окон Android alert? и изменить progressdialog background

0

1) Создайте пользовательский Java-класс Dialog, как показано выше:

Вы можете просто скопировать и вставить вышеуказанный контент в новый файл Java, никаких изменений не требуется.

package com.your.app;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

public class CustomProgressDialog extends Dialog {

public Activity c;
public Dialog d;
private String progressTitle;
private String progressComments;
private TextView tvProgressTitle;
private TextView tvProgressComments;

public CustomProgressDialog(Activity a) {
    super(a);
    // TODO Auto-generated constructor stub
    this.c = a;
}
public CustomProgressDialog(Activity a,String progressTitle,String progressComments) {
    super(a);
    // TODO Auto-generated constructor stub
    this.progressTitle = progressTitle;
    this.progressComments = progressComments;
    this.c = a;
}

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.dialog_progress);
    tvProgressTitle = (TextView) findViewById(R.id.tvProgressTitle);
    tvProgressComments = (TextView)    findViewById(R.id.tvProgressComments);
    tvProgressTitle.setText(this.progressTitle);
    tvProgressComments.setText(this.progressComments);

}
}

2) Создайте новый .xml файл с именем dialog_progress в папке вашего макета, который имеет вышеуказанный контент:

(Это просто простой пример, который выглядит как диалог прогресса по умолчанию Android, но вы можете создать свой собственный макет)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="#EDEDED"
android:orientation="vertical"
>
<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_gravity="center"
    >
    <TextView

        android:layout_marginLeft="100dp"
        android:id="@+id/tvProgressTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:layout_margin="10dp"
        android:text="Loading..."
        android:textColor="#000000"
        android:textSize="17dp"
        android:textStyle="bold"/>

</LinearLayout>

<View
    android:layout_width="wrap_content"
    android:layout_height="1dp"
    android:visibility="visible"
    android:id="@+id/ctview2"
    android:background="#000000"
     />
<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    >

    <ProgressBar
        android:layout_marginLeft="30dp"
    android:layout_gravity="center"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/progressBar"
        />

    <TextView
        android:layout_marginLeft="15dp"
        android:textColor="#000000"
        android:gravity="center"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:text="Please wait."
        android:id="@+id/tvProgressComments" />


</LinearLayout>

3) Итак, если вы хотите использовать его, просто добавьте в свою деятельность этот код:

CustomProgressDialog mprogress =  new CustomProgressDialog(MainActivity.this,"Loading...","Please wait.");
        mprogress.show();

И если вы хотите отклонить его, просто позвоните mprogress.dismiss();

Ещё вопросы

Сообщество Overcoder
Наверх
Меню