Android AlertDialog框

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文件-->
<?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();
                        }
                    });
                  

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值