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>
资源文件:
背景样式
<?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
投稿
猜你喜欢
- 本文实例讲述了Spring实战之协调作用域不同步的Bean操作。分享给大家供大家参考,具体如下:一 配置<?xml version=&
- 直接进入主题先来看一个栗子,假设现在有一个第三方dllnamespace TestLibrary1{ p
- Activity设置全屏和无标题栏,要用到andorid.view.Window和Android.view.WindowManager。 W
- 过滤器实现过滤器需要实现 javax.servlet.Filter 接口。重写三个方法。其中 init() 方法在服务启动时执行,destr
- 1.使用usb口输入的扫描枪,这里实现使用了winform首先创建一个CS文件using System;using System.Colle
- 这篇文章主要介绍了通过实例了解spring使用构造器注入的原因,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,
- 数据类型大小范围默认值byte(字节)8-128 - 1270shot(短整型)16-32768 - 327680int(整型)32-214
- 相信大家一定都使用过手机QQ和微信之类的软件,当我们使用时不难发现其界面的切换不仅可以通过点击页标签来实现,还可以通过左右滑动来实现的,耗子
- 【SpringBoot】通过Feign调用传递Header中参数如何通过Feign传递Header参数问题描述我们在SpringCloud中
- 使用mybatis-plus自动生成了5个模块(xml/bean/mapper/service/controller)的代码,这里练习一下m
- WORD: import org.apache.lucene.document.Document; import org.apache.lu
- 前言最近在研究串口通讯,其中有几个比较重要的概念,RS-232这种适配于上位机和PC端进行连接,RS-232只限于PC串口和设备间点对点的通
- if语句使用布尔表达式或布尔值作为分支条件来进行分支控制,其中if语句有如下三种形式:第一种形式:if ( logic expression
- 前言前面的例子都是多个线程在做相同的操作,比如4个线程都对共享数据做tickets–操作。大多情况下,程序中需要不同的线程做不同的事,比如一
- 一、自定义菜单的说明和按钮类型1、菜单说明1)自定义菜单最多包括3个一级菜单,每个一级菜单最多包含5个二级菜单。2)一级菜单最多4个汉字,二
- 1.什么是String?首先,初学者一定要知道String是一个类,它是字符串类型,但它不属于基本数据类。 所谓字符串类型,意思就好比将字符
- 本文实例为大家分享了Java实现人机猜拳游戏的具体代码,供大家参考,具体内容如下实现:User类public class User { pr
- 背景后台系统需要接入 企业微信登入,满足企业员工快速登入系统流程图简单代码说明自定义一套 springsecurity 认证逻辑主要就是 根
- spring cloud快速搭建Spring Cloud是一个微服务框架,它基于spring boot, Spring Cloud
- Java 字符串反转问题:给一个字符串,比如 “I love china”, 把字符反转后变成 “china love I”思路