u有另一个选择,设计了xml layout
为您的对话框如何ürequird并把它在你的活动
示例XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="215dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/custom_alert"
android:orientation="vertical" >
<TextView
android:id="@+id/tv_header"
android:layout_width="fill_parent"
android:layout_height="26dp"
android:gravity="center"
android:text="@string/oops"
android:textColor="#3f3f3f"
android:textSize="15sp"
android:textStyle="bold"
/>
<TextView
android:id="@+id/tv_description"
android:layout_width="fill_parent"
android:layout_height="58dp"
android:layout_below="@+id/tv_header"
android:gravity="center"
android:textColor="#747474"
android:textSize="10sp"
android:typeface="sans" />
<View
android:id="@+id/separator"
android:layout_width="fill_parent"
android:layout_height="1dip"
android:layout_above="@+id/tv_actionbtn"
android:layout_centerVertical="true"
android:background="#b8b8b8" />
<TextView
android:id="@+id/tv_actionbtn"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_below="@+id/tv_description"
android:gravity="center"
android:textColor="#d61820"
android:textSize="15sp"
android:typeface="sans" />
custom_alert背景布局:
<corners android:color="#FFFFFF" />
<solid android:color="#FFFFFF" />
<stroke
android:width="3dip"
android:color="#FFFFFF" />
<corners
android:radius="20dip"
android:color="#FFFFFF" />
<padding
android:bottom="0dip"
android:left="0dip"
android:right="0dip"
android:top="0dip" />
这里是活动代码
dialog = new Dialog(Activity.this);
dialog.setContentView(R.layout.customdialog);
dialog.getWindow().setBackgroundDrawable(
new ColorDrawable(android.graphics.Color.TRANSPARENT));
txtHeader = (TextView) dialog.findViewById(R.id.requiredheader);
txtDiscription = (TextView) dialog.findViewById(R.id.requireddescription;
txtHeader.setText(getResources().getString(R.string.conneting_server));
txtDiscription.setText(getResources().getString(R.string.logging_in));
dialog.setCancelable(false);
dialog.show();
到这个如此张贴[http://stackoverflow.com/questions/820398/android-change-custom-title-view-at -run-time](http://stackoverflow.com/questions/820398/android-change-custom-title-view-at-run-time) –
dialog2.setTitle(Html.fromHtml(“
到期提醒
“)); \t \t此代码适用于我的自我 – user3472001好的和快乐的编码! –