Android弹窗提示 Android自定义弹窗提示效果

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

Android弹窗提示 Android自定义弹窗提示效果

Simon66991   2021-09-12 我要评论
想了解Android自定义弹窗提示效果的相关内容吗,Simon66991在本文为您仔细讲解Android弹窗提示的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点: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>

资源文件:

背景样式

<?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>

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们