изменить фон прогрессиалог и алертилдиалог в андроиде? - PullRequest
1 голос
/ 23 марта 2011

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

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

Ответы [ 2 ]

1 голос
/ 23 марта 2011
0 голосов
/ 06 августа 2015

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();

...