1、AlertDialog框的使用
对于AlertDialog我经常使用,同时会使用自定义样式
2、用法
1、创建
AlertDialog alertDialog = new AlertDialog.Builder(Bank_48_01Activity.this).create();
2、创建一个xml文件 bank_48_adapt01
View view = View.inflate(Bank_48_01Activity.this, R.layout.bank_48_adapt01, null);
3、使用
setView() 方法即可实现自定义样式
4、显示
show()
3、设置只有点击确定按钮才消失
setCanceledOnTouchOutside(false) 方法即可
4、列子
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="提示"
android:textColor="#A9E9FD"
android:textSize="20dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@drawable/bank_48_01" />
<TextView
android:id="@+id/con"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="网络已经断开"
android:textColor="@android:color/black"
android:textSize="20dp" />
<TextView
android:id="@+id/qd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="确定"
android:gravity="center"
android:textColor="@android:color/black"
android:textSize="20dp" />
</LinearLayout>
AlertDialog alertDialog = new AlertDialog.Builder(Bank_48_01Activity.this).create();
alertDialog.setCanceledOnTouchOutside(false);
View view = View.inflate(Bank_48_01Activity.this, R.layout.bank_48_adapt01, null);
alertDialog.setView(view);
alertDialog.show();
TextView con;
TextView qd;
con = (TextView) view.findViewById(R.id.con);
qd = (TextView) view.findViewById(R.id.qd);
con.setText("网络已经断开");
qd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertDialog.dismiss();
}
});