求一个安卓程序,要求进入程序以后就会html弹出确认对话框一个对话框,点击确认后继续html弹出确认对话框,html弹出确认对话框5个普通对话框以后html弹出确认对话框

&&国之画&&&& &&&&
版权所有 京ICP备号-2
迷上了代码!Android常用的五种弹出对话框
一个Android开发中常用对话框的小例子,共有五种对话框:普通弹出对话框,单选对话框,多选对话框,输入对话框及进度条样式对话框:
xmlns:tools=&/tools&
android:layout_width=&match_parent&
android:layout_height=&match_parent&
android:orientation=&vertical& &
<button android:id=&@+id/common_dialog&
android:layout_width=&match_parent&
android:layout_height=&40dp&
android:text=&普通对话框&
android:textSize=&16sp&
android:layout_marginTop=&10dp& /&
<button android:id=&@+id/radio_dialog&
android:layout_width=&match_parent&
android:layout_height=&40dp&
android:text=&单选对话框&
android:textSize=&16sp&
android:layout_marginTop=&10dp& /&
<button android:id=&@+id/check_dialog&
android:layout_width=&match_parent&
android:layout_height=&40dp&
android:text=&多选对话框&
android:textSize=&16sp&
android:layout_marginTop=&10dp& /&
<button android:id=&@+id/input_dialog&
android:layout_width=&match_parent&
android:layout_height=&40dp&
android:text=&输入文字对话框&
android:textSize=&16sp&
android:layout_marginTop=&10dp& /&
<button android:id=&@+id/progress_dialog&
android:layout_width=&match_parent&
android:layout_height=&40dp&
android:text=&进度条对话框&
android:textSize=&16sp&
android:layout_marginTop=&10dp& /&</button</button</button</button</button
下面是输入内容的简单布局activity_input.xml
xmlns:tools=&/tools&
android:id=&@+id/LinearLayout1&
android:layout_width=&match_parent&
android:layout_height=&match_parent&
android:orientation=&vertical& &
<textview android:layout_width=&wrap_content&
android:layout_height=&wrap_content&
android:text=&@string/hello_world& /&
<edittext android:id=&@+id/uname&
android:layout_width=&fill_parent&
android:layout_height=&wrap_content& /&
<textview android:layout_width=&wrap_content&
android:layout_height=&wrap_content&
android:text=&@string/hello_world& /&
<edittext android:id=&@+id/upass&
android:layout_width=&fill_parent&
android:layout_height=&wrap_content& /&</edittext</textview</edittext</textview
代码及注释:
public class MainActivity extends Activity implements OnClickListener {
/**单选框模拟标题 大学*/
private final static int CHECKED_ENU = 0;
/**单选框模拟标题 高中*/
private final static int CHECKED_SEL = 1;
/**单选框模拟标题 初中*/
private final static int CHECKED_CHU = 2;
/**复选按钮状态为全选 */
private boolean[] checked = { true, true, true, false };
/**模拟的进度值 */
private int progressN
/**进度对话框 */
private ProgressDialog progressD
/**对应按钮*/
private Button commonBtn, radioBtn, checkBtn, inputBtn, progressB
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initViews();
initListeners();
/**初始化UI控件*/
private void initViews() {
monBtn = (Button) findViewById(mon_dialog);
this.radioBtn = (Button) findViewById(R.id.radio_dialog);
this.checkBtn = (Button) findViewById(R.id.check_dialog);
this.inputBtn = (Button) findViewById(R.id.input_dialog);
this.progressBtn = (Button) findViewById(R.id.progress_dialog);
/**注册按钮监听事件*/
private void initListeners() {
monBtn.setOnClickListener(this);
this.radioBtn.setOnClickListener(this);
this.checkBtn.setOnClickListener(this);
this.inputBtn.setOnClickListener(this);
this.progressBtn.setOnClickListener(this);
/**普通对话框 */
private Dialog buildAlertDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setIcon(R.drawable.ic_launcher);
builder.setTitle(&对话框&);
builder.setMessage(&您的密码不对!!&);
ImageView imageView = new ImageView(this);
imageView.setImageResource(R.drawable.mm1);
/**设置背景图片*/
builder.setView(imageView);
/**左边按钮*/
builder.setPositiveButton(&确定&, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
setTitle(&您点击的是左边确定按钮!&);
/**中间按钮*/
builder.setNeutralButton(&详情&, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
setTitle(&您点击的是中间详情按钮!&);
/**右边按钮*/
builder.setNegativeButton(&取消&, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
setTitle(&您点击的是右边取消按钮!&);
return builder.create();
/**单选按钮弹出框 */
private Dialog buildAlertDialog_radio() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setIcon(R.drawable.ic_launcher);
builder.setTitle(&对话框&);
/**单选按钮,默认高中被选中*/
builder.setSingleChoiceItems(new String[] { &大学&, &高中&, &初中&, &小学& }, 1, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
switch (which) {
case CHECKED_ENU:
setTitle(&大学&);
case CHECKED_SEL:
setTitle(&高中&);
case CHECKED_CHU:
setTitle(&初中&);
setTitle(&小学&);
builder.setPositiveButton(&确定&, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
setTitle(&您点击的是左边确定按钮!&);
builder.setNegativeButton(&取消&, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
setTitle(&您点击的是右边取消按钮!&);
return builder.create();
/**可以多选按钮弹出框 */
private Dialog buildAlertDialog_checkbox() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setIcon(R.drawable.ic_launcher);
builder.setTitle(&对话框&);
/**复选按钮*/
builder.setMultiChoiceItems(new String[] { &大学&, &高中&, &初中&, &小学& }, checked, new DialogInterface.OnMultiChoiceClickListener() {
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
setTitle(&which=& + which + &-----& + &isChecked=& + isChecked);
builder.setPositiveButton(&确定&, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
setTitle(&您点击了确定按钮!&);
builder.setNegativeButton(&取消&, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
setTitle(&您点击的是了取消按钮!&);
return builder.create();
/**含可以输入文本的弹出框 */
private Dialog buildAlertDialog_input() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setIcon(R.drawable.ic_launcher);
builder.setTitle(&对话框&);
LayoutInflater inflater = LayoutInflater.from(this);
builder.setView(inflater.inflate(R.layout.activity_input, null));
builder.setPositiveButton(&确定&, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
setTitle(&您点击的是确定按钮!&);
builder.setNegativeButton(&取消&, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
setTitle(&您点击的是取消按钮!&);
return builder.create();
/**进度对话框 */
private Dialog buildAlertDialog_progress() {
progressDialog = new ProgressDialog(this);
progressDialog.setTitle(&进度条&);
progressDialog.setMessage(&正在...........&);
/**进度条样式 */
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
/**模糊效果 */
progressDialog.setIndeterminate(false);
return progressD
/**每隔0.3秒更新一次进度 */
public void updateProgress() {
new Thread() {
public void run() {
while (progressNumber &= 100) {
progressDialog.setProgress(progressNumber++);
Thread.sleep(300);
super.run();
/**下载完后,关闭下载框 */
progressDialog.cancel();
} catch (InterruptedException e) {
e.printStackTrace();
}.start();
public void onClick(View v) {
switch (v.getId()) {
case mon_dialog:
buildAlertDialog().show();
case R.id.radio_dialog:
buildAlertDialog_radio().show();
case R.id.check_dialog:
buildAlertDialog_checkbox().show();
case R.id.input_dialog:
buildAlertDialog_input().show();
case R.id.progress_dialog:
buildAlertDialog_progress().show();
updateProgress();经验1818 米
在线时间332 小时
版本6.1.28
积分 2236, 距离下一级还需 2764 积分
积分 2236, 距离下一级还需 2764 积分
机型小米手机3 TD版
签到次数60
MIUI版本6.1.28
本帖最后由 爱你55440 于
21:26 编辑
为什么每次打电话 都会弹出一个对话框,有时候不是打10086 也会弹出窗口?
(209.41 KB, 下载次数: 1)
21:26 上传
(173.04 KB, 下载次数: 1)
21:26 上传
分享到微信朋友圈
打开微信,点击底部的“发现”,使用 “扫一扫” 即可将网页分享到我的朋友圈。
楼主说的是10086夜间提示的弹窗吧?这个貌似只有运行商能解决&
经验24727 米
在线时间908 小时
版本6.3.14
机型小米手机4
签到次数113
MIUI版本6.3.14
这个是MIUI特有的功能,快捷的进入选项
经验1818 米
在线时间332 小时
版本6.1.28
积分 2236, 距离下一级还需 2764 积分
积分 2236, 距离下一级还需 2764 积分
机型小米手机3 TD版
签到次数60
MIUI版本6.1.28
这个是MIUI特有的功能,快捷的进入选项
那怎么去掉?
经验24727 米
在线时间908 小时
版本6.3.14
机型小米手机4
签到次数113
MIUI版本6.3.14
那怎么去掉?
貌似不能去掉哦 楼主
经验3633 米
在线时间68 小时
积分 4046, 距离下一级还需 954 积分
积分 4046, 距离下一级还需 954 积分
机型小米手机3/4 WCDMA版
签到次数43
MIUI版本6.3.7
这个功能不好吗?
经验4442 米
在线时间1039 小时
版本6.3.14
积分 6026, 距离下一级还需 13974 积分
积分 6026, 距离下一级还需 13974 积分
机型小米手机3-WCDMA/CDMA版
签到次数56
MIUI版本6.3.14
帮顶!!!!让更多人看到~~~~~~~~~
经验12057 米
在线时间303 小时
版本6.3.10
MIUI7内测成员
积分 14427, 距离下一级还需 5573 积分
积分 14427, 距离下一级还需 5573 积分
机型小米手机3 TD
签到次数66
MIUI版本6.3.10
感觉还行!
经验398 米
在线时间22 小时
版本5.2.23
积分 432, 距离下一级还需 68 积分
积分 432, 距离下一级还需 68 积分
机型小米手机3 TD版
签到次数41
MIUI版本5.2.23
这个功能不好吗?
人家都说了不想要这个功能,来这儿问怎么关闭,你还专门问这个功能不好吗,无聊。
经验1818 米
在线时间332 小时
版本6.1.28
积分 2236, 距离下一级还需 2764 积分
积分 2236, 距离下一级还需 2764 积分
机型小米手机3 TD版
签到次数60
MIUI版本6.1.28
人家都说了不想要这个功能,来这儿问怎么关闭,你还专门问这个功能不好吗,无聊。 ...
答非所问。。。。。。没办法 = =&&估计是去不掉的吧
经验1265 米
在线时间37 小时
版本5.3.10
积分 1639, 距离下一级还需 361 积分
积分 1639, 距离下一级还需 361 积分
机型小米手机3/4 WCDMA版
签到次数13
MIUI版本5.3.10
通过手机发布
MIUI 3000万
MIUI 3000万发烧友纪念勋章
MIUI 2000万
MIUI 2000万发烧友纪念勋章
MIUI 7纪念勋章
MIUI五周年
MIUI五周年纪念勋章
MIUI三周年
MIUI三周年纪念勋章
已关注极客秀微信
已关注微信
关注腾讯微博
已关注腾讯微博
关注新浪微博
已关注新浪微博
小米商城购买纪念勋章
论坛APP购买小米商品获得
解答组专属勋章
解答组专属勋章
参加流量购买活动
MIUI俱乐部发烧友
MIUI俱乐部发烧友
MIUI年度优秀勋章
Copyright (C) 2016 MIUI
京ICP备号 | 京公网安备34号 | 京ICP证110507号84920人阅读
初级android(31)
Android 如何监听返回键点击事件,并创建一个退出对话框,
防止自己写的应用程序不小心点击退出键而直接退出。自己记录下这个简单的demo,备用。
注:如下代码当时是从网上copy过来的,现在忘了它出自哪个原作者了,在此说声抱歉。
源码如下:
public class BackKeyTest extends Activity
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
public boolean onKeyDown(int keyCode, KeyEvent event)
if (keyCode == KeyEvent.KEYCODE_BACK )
// 创建退出对话框
AlertDialog isExit = new AlertDialog.Builder(this).create();
// 设置对话框标题
isExit.setTitle(&系统提示&);
// 设置对话框消息
isExit.setMessage(&确定要退出吗&);
// 添加选择按钮并注册监听
isExit.setButton(&确定&, listener);
isExit.setButton2(&取消&, listener);
// 显示对话框
isExit.show();
/**监听对话框里面的button点击事件*/
DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener()
public void onClick(DialogInterface dialog, int which)
switch (which)
case AlertDialog.BUTTON_POSITIVE:// &确认&按钮退出程序
case AlertDialog.BUTTON_NEGATIVE:// &取消&第二个按钮取消对话框
Android手机常用的三个键,home键,back键及menu键。
在应用程序里我们经常会对它们经常进行一定的处理,方便用户使用。
首先我们要明确点击三个键时系统干了什么事,
如果没有进行监听处理,
点击home键时,系统默认只执行应用程序的当前显示的Activity的onStop()方法后跳出界面。
而点击back键时,系统默认执行的是应用程序当前Activity的finish()方法后跳出界面。
而点击menu键时,系统默认不进行任何处理。
这里只是一个简单的应用demo,我们可以根据自己的需要设计一个更完美的退出程序对话框。
也可以在监听到返回事件后进行其他处理,等等。
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:612095次
积分:5993
积分:5993
排名:第2385名
原创:105篇
评论:91条
(1)(1)(1)(1)(5)(4)(4)(2)(4)(4)(4)(2)(2)(7)(6)(6)(11)(9)(10)(8)(8)(9)怎样使android程序在执行到某个地方自动弹出对话框?
[问题点数:40分,结帖人Aliao523]
怎样使android程序在执行到某个地方自动弹出对话框?
[问题点数:40分,结帖人Aliao523]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
本帖子已过去太久远了,不再提供回复功能。}

我要回帖

更多关于 c 弹出确认对话框 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信