Android--万能自定义弹窗
使用的是AlertDialog
自定义弹窗呢,就是一个界面放在了AlertDialog容器弹框上。
第一步:写好你的界面 (在layout下创建system_admin_psw_alert_dialog.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="#fff"android:padding="10dp"><RelativeLayout
android:layout_width="match_parent"android:layout_height="40dp"android:layout_marginBottom="10dp"><ImageView
android:id="@+id/system_admin_psw_alert_img"android:layout_width="40dp"android:layout_height="40dp"android:background="@drawable/warn"/><TextView
android:layout_width="wrap_content"android:layout_height="40dp"android:text="@string/warning"android:textColor="#f00"android:textSize="25sp"android:layout_marginLeft="6dp"android:layout_toRightOf="@+id/system_admin_psw_alert_img"/><Button
android:id="@+id/system_admin_psw_alert_close"android:layout_width="22dp"android:layout_height="22dp"android:background="@mipmap/close_icon"android:layout_alignParentRight="true"/></RelativeLayout><TextView
android:layout_width="match_parent"android:layout_height="wrap_content"android:textColor="#f00"android:textSize="18sp"android:padding="8dp"android:lineSpacingExtra="8dp"android:text="@string/set_debug_info"/><EditText
android:id="@+id/sap_alert_dialog_edt"android:layout_width="match_parent"android:layout_height="wrap_content"android:maxLength="6"android:digits="1234567890"android:singleLine="true"android:layout_margin="16dp"android:hint="请输入主管密码"android:textColorHint="#ccc"android:textColor="#000"android:background="@mipmap/sys_login_psw"/><RelativeLayout
android:layout_width="match_parent"android:layout_height="wrap_content"android:paddingBottom="10dp"><Button
android:id="@+id/sap_alert_dialog_cancel"android:layout_width="wrap_content"android:layout_height="34dp"android:background="#f00"android:text="关闭"android:layout_marginLeft="20dp"/><Button
android:id="@+id/sap_alert_dialog_ok"android:layout_width="wrap_content"android:layout_height="34dp"android:background="#f00"android:text="开启"android:layout_alignParentRight="true"android:layout_marginRight="20dp"/></RelativeLayout></LinearLayout>
2、在一个Activity界面上设置按钮 然后触发弹框出现
再触发时间里写 showSetDeBugDialog()方法
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);//初始化控件final EditText adminPwd = (EditText) dialogView.findViewById(R.id.sap_alert_dialog_edt);Button okButton = (Button) dialogView.findViewById(R.id.sap_alert_dialog_ok);//取消点击外部消失弹窗setDeBugDialog.setCancelable(false);//创建AlertDiaLogsetDeBugDialog.create();//AlertDiaLog显示final AlertDialog customAlert = setDeBugDialog.show();//设置自定义界面的点击事件逻辑 dialogView.findViewById(R.id.system_admin_psw_alert_close).setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {customAlert.dismiss();}});okButton.setOnClickListener(new android.view.View.OnClickListener() {@Overridepublic void onClick(View view) {String str = adminPwd.getText().toString();if (str.equals("888888")) {ToastUtil.toast("开启");editor.putString("univ_set_debug", "1");editor.apply();setDebugbtn.setText(getString(R.string.debug_open));customAlert.dismiss();}else{ToastUtil.toast(getString(R.string.login_pwd_fail));}}});dialogView.findViewById(R.id.sap_alert_dialog_cancel).setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {String str = adminPwd.getText().toString();if (str.equals("888888")) {ToastUtil.toast("关闭");editor.putString("univ_set_debug", "0");editor.apply();setDebugbtn.setText(getString(R.string.debug_close));customAlert.dismiss();}else{ToastUtil.toast(getString(R.string.login_pwd_fail));}}});}
Android--万能自定义弹窗相关推荐
- Android自定义弹窗
每个APP都有自己的UI风格,不可能简单地使用Google自带的弹窗模板.所以是时候搞一套我们自己的弹窗范例代码了.按照下列代码只需要再根据APP的主题风格重新绘制一波弹窗布局,就可以无脑迁移了,这种 ...
- Android开发之PopupWindow仿QQ自定义弹窗
截图图 1.自定义弹窗布局confirm_dialog.xml <?xml version="1.0" encoding="utf-8"?> < ...
- android 自定义弹窗diss,Android中自定义PopupWindow,动态弹窗。
我的第一篇博客,咱们直奔主题.先上个效果图 在android中自定义PopupWindow: 1.首先定义好你想要显示的窗口的布局文件,再实例化一个View对象:窗口布局可灵活变化,dialog_la ...
- 使用Vitamio打造自己的Android万能播放器(2)—— 手势控制亮度、音量、缩放
前言 本章继续完善播放相关播放器的核心功能,为后续扩展打好基础. 声明 欢迎转载,但请保留文章原始出处:) 博客园:http://www.cnblogs.com 农民伯伯: http://over1 ...
- Android 万能适配器BaseQuickAdapter操作及免费源码
Android 万能适配器BaseQuickAdapter操作及免费源码,本篇巨长无比,非常详细的介绍了BaseQuickAdapter,若有帮助到您,记得点个赞哦~ 简介 导入依赖 简单使用 添加头 ...
- 使用Vitamio打造自己的Android万能播放器—— 手势控制亮度、音量、缩放
使用Vitamio打造自己的Android万能播放器(1)--准备 一.实现目标 1.1亮度控制 模仿VPlayer界面: 1.2声音控制 模仿VPlayer界面: 1.3画面缩放 根据下面API ...
- Android优雅实现弹窗优先级管理
前言 在日常的android开发中,我们或多或少都有做过应用内的一些弹窗,比如在应用的某些页面弹窗展示广告,弹窗通知消息等.你的app中使用弹窗是否比较频繁?你是否厌烦了每次敲击一大堆代码就为了展示一 ...
- Android 基于ijkplayer+Rxjava+Rxandroid+Retrofit2.0+MVP+Material Design的android万能播放器aaa
MDPlayer万能播放器 MDPlayer,基于ijkplayer+Rxjava+Rxandroid+Retrofit2.0+MVP+Material Design的android万能播放器,可以播 ...
- 基于ijkplayer+Rxjava+Rxandroid+Retrofit2.0+MVP+Material Design的android万能播放器
MDPlayer万能播放器 MDPlayer,基于ijkplayer+Rxjava+Rxandroid+Retrofit2.0+MVP+Material Design的android万能播放器,可以播 ...
最新文章
- 如何编辑PDF文件,怎么修改PDF中的文字
- html5指南针源码,《绝秘奉献》——最新超短线指南针!源码已放!(贴图 原码)...
- hdu5643 King's Game(约瑟夫环+线段树)
- 组织模式 - Introduction
- C语言字符串-字符串排序
- 基于Token进行身份验证
- 如何注册java程序为windows服务
- 触发父组件变量_Vue组件之间的传值
- 脚本化HTTP 取得响应 指定请求
- 《云计算架构技术与实践》连载(12)2.2.7 应用管理自己主动化技术
- laravel中文字模型的增删改查
- 国家铁路调度中心在哪_博慈46寸液晶拼接屏打造上海铁路局南翔站指挥中心显示系统...
- c#--实例选号器--实现打印、序列化方式保存、二维码
- Failed to scan [file:/D:/software/maven/apache-maven-repository/org/ujmp/ujmp-core/0.3.0/json-20141
- sql 自定义排序 顺序
- 江苏2021高考成绩查询全省排名,江苏高考排名查询方法,2021年江苏高考成绩位次全省排名查询...
- 中国历代各王朝鼎盛时期疆域
- 一文搞懂WiFi的所有知识点
- Mybatis【面试题】
- 微信公众号云服务器年服务费_微信公众号开发者接口费用高吗