private Dialog myDialog = null; private void ExitLogin() {
View view = LayoutInflater.from(MainActivity.this).inflate(R.layout.activity_exit_dialog, null);
Button btn_close = (Button) view.findViewById(R.id.btn_close);
Button btn_ok = (Button) view.findViewById(R.id.btn_ok);
ImageView img_close = (ImageView) view.findViewById(R.id.img_close);
img_close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
myDialog.dismiss();
}
}); btn_close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
myDialog.dismiss();
}
}); btn_ok.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
myDialog.dismiss();
}
}); myDialog = new Dialog(MainActivity.this, R.style.utils_dialog_loading_dialog_style);
myDialog.setCancelable(false);
myDialog.setContentView(view, new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT));
myDialog.show();
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bg_dialog"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" > <RelativeLayout
android:layout_width="280dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/pop_student"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"> <TextView
android:id="@+id/txt01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/black"
android:textSize="18sp"
android:text="确定要退出吗?"
android:layout_marginTop="50dp"
android:layout_marginBottom="40dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
/> <LinearLayout
android:id="@+id/layout_01"
android:layout_below="@id/txt01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/btn_close"
android:layout_width="wrap_content"
android:layout_height="43dp"
android:layout_weight="1"
android:background="@drawable/bg_dialog_button_left"
android:gravity="center"
android:textColor="@android:color/black"
android:text="取消"
android:textSize="16sp" /> <ImageView
android:id="@+id/img_line"
android:layout_width="0.5dp"
android:layout_height="43dp"
android:background="#c6c6c6" /> <Button
android:id="@+id/btn_ok"
android:text="确认"
android:layout_width="wrap_content"
android:layout_height="43dp"
android:layout_weight="1"
android:background="@drawable/bg_dialog_button_right"
android:gravity="center"
android:textColor="@android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/hint"
android:layout_alignTop="@+id/layout_01"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" /> <ImageView
android:id="@+id/img_close"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/exit_dialog_close"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" /> </RelativeLayout>
</RelativeLayout>
bg_dialog_button_left.xml
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#ffffff" />
<corners android:bottomLeftRadius="30dp"
android:bottomRightRadius="0dp"
android:topLeftRadius="0dp"
android:topRightRadius="0dp" />
<padding android:top="10dp"
android:bottom="10dp"
android:left="30dp"
android:right="30dp" />
</shape>
</item> <item android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="@color/code09" />
<corners android:bottomLeftRadius="30dp"
android:bottomRightRadius="0dp"
android:topLeftRadius="0dp"
android:topRightRadius="0dp" />
<padding android:top="10dp" android:bottom="10dp"
android:left="30dp" android:right="30dp" />
</shape>
</item>
</selector>
bg_dialog_button_right.xml
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item>
<shape android:shape="rectangle">
<solid android:color="#ffffff" />
<corners android:bottomLeftRadius="0dp" android:bottomRightRadius="30dp"
android:topRightRadius="0dp" android:topLeftRadius="0dp"/>
<padding android:right="25dp" android:left="25dp" android:top="10dp"
android:bottom="10dp" />
</shape>
</item> <item android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="@color/code09" />
<padding android:bottom="10dp" android:top="10dp"
android:left="25dp" android:right="25dp"/>
<corners android:bottomLeftRadius="0dp" android:bottomRightRadius="30dp"
android:topRightRadius="0dp" android:topLeftRadius="0dp"/>
</shape>
</item> </selector>