`

AlertDialog窗口

 
阅读更多

一、AlertDialog窗口的新建和显示

 

new AlertDialog.Builder(EX03_12.this)
						.setTitle(R.string.app_about)
						.setMessage(R.string.app_about_msg)
						.setPositiveButton(R.string.str_ok,
								new DialogInterface.OnClickListener() {
									public void onClick(
											DialogInterface dialoginterface,
											int i) {
										dialoginterface.cancel();
									}
								}).show();

 

二、新建具有菜单功能的AlertDialog窗口

 

new AlertDialog.Builder(MultiAlertDialog.this)
		.setTitle(R.string.app_name)
		.setItems(R.array.items,
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog,
							int whichcountry) {
						String[] aryShop = getResources()
								.getStringArray(
										R.array.items);
						new AlertDialog.Builder(MultiAlertDialog.this)
								.setMessage(aryShop[whichcountry])
								.setNeutralButton(
										"确定",
										new DialogInterface.OnClickListener() {
											public void onClick(DialogInterface dialog,int whichButton) { 
												/* 在这里处理要作的事 */
											}
										}).show();
					}
				})
		.setNegativeButton("取消",
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface d, int which) {
						d.dismiss();
					}
				}).show();



 

二、返回键AlertDialog窗口提示退出

 

public boolean onKeyDown(int keyCode, KeyEvent event) {

		if(keyCode == KeyEvent.KEYCODE_BACK){

			new AlertDialog.Builder(this)

				.setIcon(android.R.drawable.ic_menu_help)

				.setTitle("提示")

				.setMessage("您确定要退出" + getResources().getString(R.string.app_name) + "?")

				.setNegativeButton("取消", new DialogInterface.OnClickListener() {

					public void onClick(DialogInterface dialog, int which) {

					}

				})

				.setPositiveButton("确定", new DialogInterface.OnClickListener() {

					public void onClick(DialogInterface dialog, int whichButton) {

						android.os.Process.killProcess(android.os.Process.myPid());     //获取PID

					}

				}).show();		

			return true;

		}else{		

			return super.onKeyDown(keyCode, event);

		}

	}
 


 

 

  • 大小: 18.6 KB
  • 大小: 13.4 KB
  • 大小: 45.4 KB
分享到:
评论

相关推荐

    Google.Android.SDK开发范例大全

     3.12 具有交互功能的对话框——AlertDialog窗口   3.13 置换文字颜色的机关——Button与TextView的交互   3.14 控制不同的文字字体——Typeface对象使用   3.15 如iPhone拖动相片特效——Gallery画廊  ...

    Google Android SDK开发范例大全 源码

     3.12 具有交互功能的对话框——AlertDialog窗口   3.13 置换文字颜色的机关——Button与TextView的交互   3.14 控制不同的文字字体——Typeface对象使用   3.15 如iPhone拖动相片特效——Gallery画廊  ...

    Google Android SDK开发范例大全(PDF高清完整版3)(4-3)

    3.12 具有交互功能的对话框——AlertDialog窗口 3.13 置换文字颜色的机关——Button与TextView的交互 3.14 控制不同的文字字体——Typeface对象使用 3.15 如iPhone拖动相片特效——Gallery画廊 3.16 自制计算器——...

    Google Android SDK开发范例大全(PDF完整版4)(4-4)

    3.12 具有交互功能的对话框——AlertDialog窗口 3.13 置换文字颜色的机关——Button与TextView的交互 3.14 控制不同的文字字体——Typeface对象使用 3.15 如iPhone拖动相片特效——Gallery画廊 3.16 自制计算器——...

    Google Android SDK开发范例大全(PDF高清完整版1)(4-1)

    3.12 具有交互功能的对话框——AlertDialog窗口 3.13 置换文字颜色的机关——Button与TextView的交互 3.14 控制不同的文字字体——Typeface对象使用 3.15 如iPhone拖动相片特效——Gallery画廊 3.16 自制计算器——...

    Google Android SDK开发范例大全(完整版)

    3.12 具有交互功能的对话框——AlertDialog窗口 3.13 置换文字颜色的机关——Button与TextView的交互 3.14 控制不同的文字字体——Typeface对象使用 3.15 如iPhone拖动相片特效——Gallery画廊 3.16 自制计算器——...

    Google Android SDK开发范例大全的目录

    3.12 具有交互功能的对话框——AlertDialog窗口 3.13 置换文字颜色的机关——Button与TextView的交互-p60 3.14 控制不同的文字字体——Typeface对象使用 3.15 如iPhone拖动相片特效——Gallery画廊 3.16 自制计算器...

    Google Android SDK开发范例大全(完整版附部分源码).pdf

    3.12 具有交互功能的对话框——AlertDialog窗口 3.13 置换文字颜色的机关——Button与TextView的交互 3.14 控制不同的文字字体——Typeface对象使用 3.15 如iPhone拖动相片特效——Gallery画廊 3.16 自制计算器...

    Google+Android+SDK开发范例大全

    3.12 具有交互功能的对话框——AlertDialog窗口 3.13 置换文字颜色的机关——Button与TextView的交互 3.14 控制不同的文字字体——Typeface对象使用 3.15 如iPhone拖动相片特效——Gallery画廊 3.16 自制计算器——...

    Google Android sdk 开发范例大全 部分章节代码

    3.12 具有交互功能的对话框——AlertDialog窗口 3.13 置换文字颜色的机关——Button与TextView的交互-p60 3.14 控制不同的文字字体——Typeface对象使用 3.15 如iPhone拖动相片特效——Gallery画廊 3.16 自制计算器...

    Google Android SDK 开发范例大全01

    3.12 具有交互功能的对话框——AlertDialog窗口 3.13 置换文字颜色的机关——Button与TextView的交互-p60 3.14 控制不同的文字字体——Typeface对象使用 3.15 如iPhone拖动相片特效——Gallery画廊 3.16 自制计算器...

    Google Android SDK 开发范例大全02

    3.12 具有交互功能的对话框——AlertDialog窗口 3.13 置换文字颜色的机关——Button与TextView的交互-p60 3.14 控制不同的文字字体——Typeface对象使用 3.15 如iPhone拖动相片特效——Gallery画廊 3.16 自制计算器...

    AlertDialog加载动画弹出框

    AlertDialog加载动画弹出框,内置注释,以及AlertDialog属性设置,窗口背景,样式设置,全部设置,下载完了看ChrysanthemumActivity类其他类不用管

    Alertdialog的设计

    layout窗口设计和非layout型窗口设计 alertdialog实现代码

    android使用MaterialDialog和AlertDialog弹框Timer倒计时的用法

    安卓使用弹框做到倒计时的用法,分别使用MaterialDialog、AlertDialog来做了一个小demo

    alertDialog.rar_对话框与窗口_Java_

    alertdialog自定义,大家可以看看哟,挺不错的

    Android中AlertDialog 点击按钮后不关闭对话框的功能

    当我点击确定按钮,也就是 AlertDialog 里的 PositiveButton 的时候,我们需要判断用户是输入是否符合我们的预期,如果不符合通常提示用户重写输入,且不关闭当前的对话框,但上图中点击按钮后会自动的关闭窗口。...

    Android编程之交互对话框实例浅析

    1. 在Android SDK中,虽然有许多的窗口,有些类似Modeless的窗口、有些类似于前端Force Focus的窗口,但真正具有交互功能的则为AlertDialog对话窗口。 new AlertDialog.Builder(EX03_12.this) .setTitle(R.string....

Global site tag (gtag.js) - Google Analytics