我在我的应用程序中有一个alertdialog和进度对话框。我希望我的进度对话框和警报对话框看起来与iphone中的一样。我如何改变它们的背景来实现这一目标?在android中更改progressdialog和alertdialog背景?
编辑: 也可以使用自定义视图来实现这种效果吗?扩展进度对话类的东西.....? 感谢您的帮助。
我在我的应用程序中有一个alertdialog和进度对话框。我希望我的进度对话框和警报对话框看起来与iphone中的一样。我如何改变它们的背景来实现这一目标?在android中更改progressdialog和alertdialog背景?
编辑: 也可以使用自定义视图来实现这种效果吗?扩展进度对话类的东西.....? 感谢您的帮助。
1)创建一个自定义对话框的java类,像这样的上面:
你可以简单的复制和粘贴以上内容到新的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)创建一个名为在具有上述内容的布局文件夹dialog_progress
一个新的.xml文件:
(这只是一个简单的例子,看起来像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();
可能重复[我怎样才能更改Android警报对话框的背景?](http://stackoverflow.com/questions/3118601/how-can-i-change-the-background-of-android-alert-dialogs) – 2012-06-30 09:50:53