软件编程
位置:首页>> 软件编程>> Android编程>> Android自定义弹窗提示效果

Android自定义弹窗提示效果

作者:Simon66991  发布时间:2022-05-13 12:00:14 

标签:Android,弹窗提示

本文实例为大家分享了Android 自定义弹窗提示的具体代码,供大家参考,具体内容如下

Java文件:


private void showSetDeBugDialog() {
       AlertDialog.Builder setDeBugDialog = new AlertDialog.Builder(this);
       //获取界面
       View dialogView = LayoutInflater.from(this).inflate(R.layout.system_admin_psw_alert_dialog, null);
       //将界面填充到AlertDiaLog容器并去除边框
       setDeBugDialog.setView(dialogView,0,0,0,0);
       //初始化控件
       TextView but_cancel = dialogView.findViewById(R.id.but_cancel);
       TextView but_confirm = dialogView.findViewById(R.id.but_confirm);
       //取消点击外部消失弹窗
       setDeBugDialog.setCancelable(false);
       //创建AlertDiaLog
       setDeBugDialog.create();
       //AlertDiaLog显示
       final AlertDialog customAlert = setDeBugDialog.show();
       //设置AlertDiaLog宽高属性
//        WindowManager.LayoutParams params = Objects.requireNonNull(customAlert.getWindow()).getAttributes();
//        params.width = 200;
//        params.height = 200 ;
//        customAlert.getWindow().setAttributes(params);
       // 移除dialog的decorview背景色
       Objects.requireNonNull(customAlert.getWindow()).getDecorView().setBackground(null);
       //设置自定义界面的点击事件逻辑
       but_cancel.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View view) {
               customAlert.dismiss();
           }
       });
       but_confirm.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View view) {
               customAlert.dismiss();
           }
       });
   }

布局文件:


<?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"
   android:background="@drawable/fillet_fill_stroke">

<ImageView
       android:layout_width= "38dp"
       android:layout_height="38dp"
       android:layout_marginLeft="10dp"
       android:layout_marginTop="10dp"
       android:src="@mipmap/wenti"/>

<TextView
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:gravity="center"
       android:paddingTop="20dp"
       android:paddingBottom="20dp"
       android:textColor="#5C5C5C"
       android:textSize="20sp"
       android:layout_marginLeft="15dp"
       android:layout_marginRight="15dp"
       android:text="确定要退出吗?"/>

<LinearLayout
       android:layout_width="match_parent"
       android:layout_height="1dp"
       android:background="#eee"/>

<LinearLayout
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:orientation="horizontal">

<TextView
           android:id="@+id/but_cancel"
           android:layout_width="0dp"
           android:layout_height="wrap_content"
           android:layout_weight="1"
           android:gravity="center"
           android:textColor="#999"
           android:paddingTop="15dp"
           android:paddingBottom="15dp"
           android:text="取消"/>

<LinearLayout
           android:layout_width="1dp"
           android:layout_height="match_parent"
           android:background="#eee"/>

<TextView
           android:id="@+id/but_confirm"
           android:layout_width="0dp"
           android:layout_height="wrap_content"
           android:layout_weight="1"
           android:gravity="center"
           android:paddingTop="15dp"
           android:paddingBottom="15dp"
           android:textColor="#5C5C5C"
           android:textStyle="bold"
           android:text="确定"/>

</LinearLayout>

</LinearLayout>

资源文件:

Android自定义弹窗提示效果

背景样式


<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

<!--描边设置-->
   <stroke android:color="@android:color/darker_gray"
       android:width="1px" />

<!--填充设置-->
   <solid android:color="@android:color/white"/>

<!--圆角设置-->
   <corners android:radius="15dp"/>

</shape>

来源:https://blog.csdn.net/weixin_44177244/article/details/111170188

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com