安卓中的对话框通知---简单的对话框入门

当你的应用需要显示一个进度条或需要用户对信息进行确认时,可以使用对话框来完成。

1、用一个按钮来进行测试,在layout文件中的activity_main.xml文件中添加一个Button按钮:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:paddingBottom="@dimen/activity_vertical_margin"android:paddingLeft="@dimen/activity_horizontal_margin"android:paddingRight="@dimen/activity_horizontal_margin"android:paddingTop="@dimen/activity_vertical_margin"tools:context=".MainActivity" ><Buttonandroid:id="@+id/button1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentLeft="true"android:layout_alignParentRight="true"android:layout_alignParentTop="true"android:onClick="openDialog"android:text="@string/text_dialog" /></RelativeLayout>


2、MainActivity中的代码:

package com.example.lession16_dialog;import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.view.View;public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);}public void openDialog(View v) {new AlertDialog.Builder(this).setIcon(R.drawable.ic_launcher).setTitle("xxxx").setMessage("是否创建文件").setPositiveButton("确认", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {// 创建文件了new AlertDialog.Builder(MainActivity.this).setMessage("文件已经被创建").show();}}).setNegativeButton("取消", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {new AlertDialog.Builder(MainActivity.this).setMessage("您已经选择了取消的按钮,该文件不会被创建").create().show();}}).show();}public void test1() {// 创建对话框对象AlertDialog alertDialog = new AlertDialog.Builder(this).create();// 设置对话框的标题alertDialog.setTitle("XXXXX");// 设置对话框中的内容alertDialog.setMessage("消息");// 显示对话框alertDialog.show();}public void tes2() {AlertDialog alertDialog = new AlertDialog.Builder(this).setTitle("xxxx").setMessage("xxxx").show();}}


注:MainActivity中的test1和test2分别是两种显示Dialog的方法,openDialog也是一种,只不过常用openDialog中的方法,不过还是要看大家的习惯了!

 

转载于:https://www.cnblogs.com/jiangu66/p/3155423.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/274186.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

mac photoshop_我讨厌Photoshop…

mac photoshopIt probably sounds odd to hear a visual designer say they hate Photoshop. It’s sort of like hearing a writer say they hate Word. It’s sort of a given that Photoshop is the medium within which visual designers work their magic. It’s also one…

PHP中的ob_start用法详解

用PHP的ob_start();控制您的浏览器cache Output Control 函数可以让你自由控制脚本中数据的输出。它非常地有用&#xff0c;特别是对于&#xff1a;当你想在数据已经输出后&#xff0c;再输出文件头的情况。输出控制函数不对使用 header() 或 setcookie(), 发送的文件头信息产生…

做事用人 用人做事_做事:构建我的第一个Web应用程序的经验教训

做事用人 用人做事On the 5th of June, 2020, after almost two weeks of (re)learning javascript, fixing bugs, creating new ones and of course, lots of testing, I launched Writty on ProductHunt. An open-source text editor to help anyone who is into writing to …

[转]C#委托的异步调用

本文将主要通过“同步调用”、“异步调用”、“异步回调”三个示例来讲解在用委托执行同一个“加法类”的时候的的区别和利弊。 首先&#xff0c;通过代码定义一个委托和下面三个示例将要调用的方法&#xff1a; /*添加的命名空间using System.Threading;using System.Runtime.…

vista下载_Vista和视图在游戏设计中的功能

vista下载Views in video games are observation points used to highlight a lot of objects into one frame or shot using a special camera move. Vistas are special types of views that show distant objects, mainly far off landscapes.电子游戏中的视图是观察点&…

微软开始提供公共预览版Windows 8.1下载

用户可在微软发布官方更新时免费下载Windows 8.1&#xff0c;这个最新版本的Windows 8系统对搜索系统作出了改进&#xff0c;此外还修改了Windows Store&#xff0c;并对核心应用进行了升级。Windows 8.1还重新推出了“开始”按钮&#xff0c;并对用户界面作出了多处修改。虽然…

keynote使用手册_如何使用Keynote和智能手机为AR创建原型

keynote使用手册Designing for AR is perhaps one of the most interesting applications of UX. As this incredible technology is being put to use for unique applications, UX Designers are tasked with creating user interfaces for an augmented experience, that do…

我会永远永远的爱你,直到你不爱我的那一天

【one】电话铃声响起的时候&#xff0c;林岫正好解下衣服的最后一颗纽扣。她站在原地&#xff0c;看着桌面上不断震动的手机&#xff0c;很久都没有接。“林医生&#xff0c;你的电话”&#xff0c;有同事在身旁好心的提醒。她依然没有动&#xff0c;只是静静注视着那个手机&am…

HTML5工具

HTML5工具 HTML&#xff08;Hyper Text Mark-up Language &#xff09;即超文本标记语言&#xff0c;自万维网初创之日起&#xff0c;它就已经成为满意度很高的公共语言。在过去的两年里&#xff0c;HTML5在性能上得到了很大的提升和改进&#xff0c;当仁不让的获得了大众的青睐…

远程控制工具_不要让您的工具控制您

远程控制工具When to Use Optical Alignment — You’re the Designer. You Know What’s Best.何时使用光学对准—您是设计师。 你知道什么是最好的。 Let’s talk about the tools the vast majority of us use on a day to day basis… These tools are Incredibly powerfu…

模态和非模态代码_我们如何使模态可用和可访问?

模态和非模态代码什么是模态&#xff1f; (What are modals?) A modal, or modal dialog, is an overlay window that opens on top of the current primary content or screen. It places focus on itself, usually making the background inactive (“inert”) — i.e. visu…

如何查看数据文件或者Log文件是否增长过?

在论坛看到一个帖子&#xff0c;说数据库变慢了一段时间&#xff0c;发现这段时间数据库文件的最后修改时间跟变慢的世界一致&#xff0c;想知道这段时间是否文件确实增长了。 其实SQL Server提供了数据增长的Event&#xff0c;而且Default Trace里面就记录了。 下面我们做个测…

软件项目开发 学校自行开发_自行开发游戏

软件项目开发 学校自行开发Making a game is not easy. Quite the contrary; it’s an incredibly difficult and daunting task. Game development typically takes teams of people, thousands of hours worth of labor, and hundreds of thousands — if not millions — of…

jquery Fancybox使用教程

jquery Fancybox使用教程 Fancybox是一款基于jquery的对图片展示播放的插件&#xff0c;当然&#xff0c;它html文本、flash动画、iframe以及ajax也予以支持。还可以通过css自定义外观&#xff0c;阴影效果超级赞&#xff01; 演示效果&#xff1a;http://www.phpddt.com/demo/…

优衣库不雅_Uniqlo主页-用户体验案例研究

优衣库不雅I am a big fan of Uniqlo because they sell innovative clothing that is great quality at great prices. So when all their stores closed during the “Covid-19 Circuit Breaker” in Singapore, I turned to their website and was surprised how difficult …

PHP生成缩略图函数

function img_create_small($big_img, $width, $height, $small_img) { // 大图文件地址&#xff0c;缩略宽&#xff0c;缩略高&#xff0c;小图地址$imgage getimagesize($big_img); //获取大图信息switch ($imgage[2]) { // 判断图像类型case 1:$im imagecreatefromgif($bi…

shields 徽标_到处都有平面徽标

shields 徽标重点 (Top highlight)Companies invest a lot of time, money and energy trying to make audiences remember their logos and associate higher value with it. The end goal is to make customers pick their brand over another brand. 公司投入了大量的时间&a…

jquery锚点连接划动滚动条,再也不用a标签name 了

$("html,body").animate({ scrollTop: $(".reviews_list").children("ul").children("li").children("b:last").offset().top }, 1000); 转载于:https://www.cnblogs.com/gxmaspx/p/3169931.html

登录,注册,登录,登录..?

Last year I found myself in an interesting conversation about which copy to use for a website’s sign up journey. And it wasn’t the first time. Often this devolves into an opinion-based discussion among stakeholders of the ‘what-I-like-based-on-no-eviden…

未完成的控件

using System; using System.ComponentModel; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms;namespace ImageControls {/// <summary>/// 控件/// </summary> public class ShapeEx : Control{#region 字段private Color _B…