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

发布时间:2021-09-13 09:53:01 作者:chen
来源:亿速云 阅读:203

本篇内容主要讲解“Android怎么自定义弹窗提示效果”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“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>

到此,相信大家对“Android怎么自定义弹窗提示效果”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

推荐阅读:
  1. JQ制作简易弹窗效果
  2. jquery如何实现弹窗效果

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

android

上一篇:Python如何搭建爬虫程序

下一篇:如何使用C#开发微信企业号的通讯录管理之成员管理

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》