1:实现方法
private void showCancelDialog() {
// TODO Auto-generated method stub
AlertDialog.Builder builder=new AlertDialog.Builder(this);
dialog=builder.create();
dialog.show();
final Window window = dialog.getWindow();
window.setContentView(R.layout.dialog_cancel);
Button cancelBtn=(Button)window.findViewById(R.id.cancel_btn);
Button continueBtn=(Button)window.findViewById(R.id.continue_btn);
cancelBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
finish();
}
});
continueBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
dialog.dismiss();
}
});
}
2.对话框布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="270dp"
android:layout_height="wrap_content"
android:gravity="center"
android:background="@drawable/dialog_background"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="23dp"
android:gravity="center"
android:text="放弃创建店铺"
android:textColor="#000000"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="18dp"
android:layout_marginRight="18dp"
android:layout_marginTop="12dp"
android:text="第一个发现该店的人是你,真的要放弃创建店铺吗?"
android:textColor="#454545"
android:textSize="18sp" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_marginTop="25dp"
android:layout_height="53dp"
android:orientation="vertical"
android:gravity="bottom" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="1px"
android:background="@color/div_line_b" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="52dp"
android:gravity="center" >
<Button
android:id="@+id/cancel_btn"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@null"
android:text="放弃"
android:textColor="#017aff"
android:textSize="18sp" />
<LinearLayout
android:layout_width="1px"
android:layout_height="fill_parent"
android:background="@color/div_line_b"
></LinearLayout>
<Button
android:id="@+id/continue_btn"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@null"
android:text="继续创建"
android:textColor="#017aff"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
3:对话框背景
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#d8e0de" />
<stroke
android:width="1dp"
android:color="@color/div_line_b" />
<corners android:radius="10dp" />
<padding
android:bottom="0dp"
android:left="0dp"
android:right="0dp"
android:top="0dp" />
</shape>
<img src="https://img-blog.csdn.net/20150203105558087?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGlhbndhbmZlaQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />