AS之AlertDialog使用
关于AlertDialog的使用,主要是去做一个弹窗。
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Toast; import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity; public class LayoutActivity extends AppCompatActivity implements View.OnClickListener{
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout);
Button btn_alert=findViewById(R.id.btn_alert);
btn_alert.setOnClickListener(this);
}
@Override
public void onClick(View v) {
AlertDialog.Builder builder=new AlertDialog.Builder(this);
builder.setTitle("").setIcon(R.mipmap.ic_launcher).setMessage("要更新新版本吗?")
.setPositiveButton("好的", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(LayoutActivity.this, "系统正在更新...", Toast.LENGTH_SHORT).show();
}
}).setNegativeButton("不用了,谢谢", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(LayoutActivity.this, "您已取消更新...", Toast.LENGTH_SHORT).show();
}
});
AlertDialog ad=builder.create();
ad.show();
}
}
运行结果:



AS之AlertDialog使用的更多相关文章
- Stack Overflow 排错翻译 - Closing AlertDialog.Builder in Android -Android环境中关闭AlertDialog.Builder
Stack Overflow 排错翻译 - Closing AlertDialog.Builder in Android -Android环境中关闭AlertDialog.Builder 转自:ht ...
- Android中的AlertDialog使用示例五(自定义对话框)
在Android开发中,我们经常会需要在Android界面上弹出一些对话框,比如询问用户或者让用户选择.这些功能我们叫它Android Dialog对话框,AlertDialog实现方法为建造者模式. ...
- android 弹出AlertDialog的学习案例
我在编写的时候,测试的关键代码: AlertDialog.Builder builder=new AlertDialog.Builder(MainPointListActivity.this); bu ...
- The method setPositiveButton(int, DialogInterface.OnClickListener) in the type AlertDialog.Builder is not applicable for the arguments
The method setPositiveButton(int, DialogInterface.OnClickListener) in the type AlertDialog.Builder i ...
- setView的AlertDialog在受到二次点击后出错
错误报告: 10-21 13:11:16.009: E/AndroidRuntime(27937): FATAL EXCEPTION: main10-21 13:11:16.009: E/Androi ...
- 关于AlertDialog.Builder(Context context)中所应传入的context
错误报告: 10-20 14:34:46.565: E/AndroidRuntime(23098): FATAL EXCEPTION: main10-20 14:34:46.565: E/Androi ...
- 安卓 自定义AlertDialog对话框(加载提示框)
AlertDialog有以下六种使用方法: 一.简单的AlertDialog(只显示一段简单的信息) 二.带按钮的AlertDialog(显示提示信息,让用户操作) 三.类似ListView的Aler ...
- Android AlertDialog去除黑边白边自定义布局(转)
LayoutInflater inflater = this.getLayoutInflater(); View view = inflater.inflate(R.layout.test_alert ...
- Android开发2:事件处理及实现简单的对话框(Toast,AlertDialog,Snackbar,TextInputLayout的使用)
前言 啦啦啦~又要和大家一起学习Android开发啦,博主心里好激动哒~ 在上篇博文中,我们通过线性布局和基础组件的使用,完成了一个简单的学生课外体育积分电子认证系统的界面,本篇博文,将和大家一起熟悉 ...
- Android中的AlertDialog使用示例四(多项选择确定对话框)
在Android开发中,我们经常会需要在Android界面上弹出一些对话框,比如询问用户或者让用户选择.这些功能我们叫它Android Dialog对话框,AlertDialog实现方法为建造者模式. ...
随机推荐
- IEAD关于git配置以及拉代码和提交代码
1.提前安装git客户端,注册码云帐号 注册地址:https://gitee.com/signup 2.新建仓库 3.修改仓库信息 4.从IDEA拉git项目,下面两个地方都可以配置 首次创建需要输入 ...
- 开源版-阿里云人脸搜索M:N,人脸比对1:1
一.人脸搜索概要 本项目是阿里云视觉智能开放平台的人脸1:N的开源替代,项目中使用的模型均为开源模型,项目支持milvus和proxima向量存储库,并具有较高的自定义能力. 项目使用纯Java开发, ...
- CSV格式的文件与EXCEL文件的区别
CSV格式的文件与EXCEL文件的区别 Excel CSV 这是一个二进制文件,它保存有关工作簿中所有工作表的信息 CSV代表Comma Separated Values .这是一个纯文本格式,用逗号 ...
- 74CMS 3.0 SQL注入漏洞前台
一. 启动环境 1.双击运行桌面phpstudy.exe软件 2.点击启动按钮,启动服务器环境 二.代码审计 1.双击启动桌面Seay源代码审计系统软件 2.因为74CMS3.0源代码编辑使用GBK编 ...
- ShellExecuteA加载exe文件指定工作目录找不到文件的问题
使用ShellExecuteA调用exe文件时,指定工作目录需要注意 函数原型为: HINSTANCE ShellExecuteA( HWND hwnd, LPCTSTR lpOperation, L ...
- 开启 Spring Boot 特性有哪几种方式?
1)继承spring-boot-starter-parent项目 2)导入spring-boot-dependencies项目依赖
- 什么是 Hystrix 断路器?我们需要它吗?
由于某些原因,employee-consumer 公开服务会引发异常.在这种情况下使用Hystrix 我们定义了一个回退方法.如果在公开服务中发生异常,则回退方法返回一些默认值. 如果 firstPag ...
- Springmvc入门基础(五) ---controller层注解及返回类型解说
0.@Controller注解 作用:通过@Controller注解,注明该类为controller类,即控制器类,需要被spring扫描,然后注入到IOC容器中,作为Spring的Bean来管理,这 ...
- Springmvc入门基础(三) ---与mybatis框架整合
1.创建数据库springmvc及表items,且插入一些数据 DROP TABLE IF EXISTS `items`; CREATE TABLE `items` ( `id` int(11) NO ...
- SpringBoot打包成可执行的Jar文件
需要时SpringBoot项目 通过创建可以在生产环境中运行的完全独立的可执行jar文件来结束示例.可执行jar(有时称为"胖jar")是包含您的已编译类以及代码需要运行的所有ja ...