我没有使用alertDialog,而是使用了Dialog。获得自定义外观:
1-创建对话框并删除标题区域(否则您将在顶部看到空白的灰色区域):
myDialog = new Dialog(this);myDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
2-在xml中设计一个布局,并将其设置为对话框的内容:
myDialog.setContentView(R.layout.mydialog_layout);
3-如果布局不是圆角的rect,则它将与对话框的圆角相交。因此,将布局设计为圆角矩形:
在mydialog_layout.xml中:
android:background = "@layout/mydialog_shape"
mydialog_shape.xml:
<?xml version="1.0" encoding="UTF-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <gradient android:startColor="#FF0E2E57" android:endColor="#FF0E2E57" android:angle="225" android:paddingLeft="20dip"/> <corners android:bottomRightRadius="5dp" android:bottomLeftRadius="5dp" android:topLeftRadius="5dp" android:topRightRadius="5dp" android:paddingLeft="20dip"/> </shape>
4-将侦听器添加到活动中的按钮:
Button button = (Button)myDialog.findViewById(R.id.dialogcancelbutton);button.setonClickListener(new onClickListener() {@Overridepublic void onClick(View v) { // TODO Auto-generated method stub myDialog.cancel();}});就是这样



