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


猜你喜欢
- Android 获取手机信息应用信息:包名、版本号、版本名,手机是否有Root权限手机信息:手机屏幕宽和高、当前可用内存大小、总内存大小、I
- 这个窗口是右下角提示小窗口,主要用于提示。private void btnStartNotification_Click(object se
- 实现思路收集路径点集。平均采样路径点集。将路径点集转为 LineB。把 LineB 数据传给 Pat
- 首先从表现层介绍,后续后深入原理。1、先简单介绍maven如何生成jar文件方便测试<plugin>
- 场景随着移动支付的兴起,在我们的app'中,会经常有集成支付的需求.这时候一般都会采用微信和支付宝的sdk 来集成(一)支付宝支付在
- 线程可以理解为下载的通道,一个线程就是一个文件的下载通道,多线程也就是同时开启好几个下载通道。当服务器提供下载服务时,使用下载者是共享带宽的
- 手把手教你用C#开发Android应用程序的方法和流程摘要:用C#能开发RFID-android吗?C#真的能开发android程序吗?C#
- 本文实例为大家分享了Android联系人字母排序的具体代码,供大家参考,具体内容如下实现思路:首先说下布局,整个是一个相对布局,最下面是一个
- 本文实例为大家分享了Android实现时钟特效的具体代码,供大家参考,具体内容如下效果展示:功能介绍:如果您想换一张背景图,可以点击左下角按
- 本文实例讲述了Android开发实现标题随scrollview滑动变色的方法。分享给大家供大家参考,具体如下:要实现某个view的背景透明度
- 代码很简单,直接上代码,大家参考使用吧package com.it.login.service;import java.io.Buffere
- 现象在日志配置文件 logback-spring.xml 中,无论怎么修改级别,mybatis 的 sql 日志都会打印出来。原因在 app
- 一、前言WPF没有内置IP地址输入控件,因此我们需要通过自己定义实现。我们先看一下IP地址输入控件有什么特性:输满三个数字焦点会往右移键盘←
- 在线程中有两种常用的方法,能够通过数组实现相应的功能,但除此之外在区别上也是很明显的。本篇就其中的代表方法ArrayList和Vector进
- Java接口回调产生接口回调的场景在现实生活中,产生接口回调的场景很简单,比如我主动叫你帮我做一件事,然后你做完这件事之后会通知我,&quo
- java内存分析类加载的过程类的加载与ClassLoader的理解类的初始化package Collections;public class
- 只需要在控件TextBox的keypress事件中写入如下代码即可满足要求:代码如下:if (e.KeyChar == '.'
- 最近在通讯录新建联系人=中,一进入一个页面, EditText默认就会自动获取焦点,很是郁闷, 如何让EditText不自动获取焦点?那么如
- 前言之前看到某公司的官网的文章的浏览量刷新一次网页就会增加一次,给人的感觉不太好,一个公司的官网给人如此直白的漏洞,我批量发起请求的时候发现
- 一、语音聊天说专业点就是即时语音,是一种基于网络的快速传递语音信息的技术,普遍应用于各类社交软件中,优势主要有以下几点:(1)时效性:视频直