Android 常用对话框
来源:互联网 发布:js 前后端数据 交互 编辑:程序博客网 时间:2024/06/06 00:10
1.最简单的Toast
public void toast(View v) {Toast.makeText(getApplicationContext(), "Toast通知", Toast.LENGTH_SHORT).show();}
2.状态栏通知
public void stateBar(View v) {NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);Notification notification = new Notification(R.drawable.qq, "下载完成",System.currentTimeMillis());Intent intent = new Intent();intent.setClassName("com.swust.Downloder","com.swust.Downloder.MainActivity");PendingIntent pendingIntent = PendingIntent.getActivity(this, 100,intent, PendingIntent.FLAG_ONE_SHOT);notification.setLatestEventInfo(this, "QQ下载完成", "QQ2013下载完成,耗时:2分15秒",pendingIntent);notification.flags = Notification.FLAG_AUTO_CANCEL;manager.notify(0, notification);}
3.普通对话框
public void common(View v) {OnClickListener listener = new OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {// TODO Auto-generated method stubString msg = "";switch (which) {case DialogInterface.BUTTON_POSITIVE:msg = "确定";break;case DialogInterface.BUTTON_NEGATIVE:msg = "取消";break;case DialogInterface.BUTTON_NEUTRAL:msg = "稍后";break;}Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT).show();}};new Builder(this).setTitle("是否下载新版本").setMessage("1.速度更快\r\n2.更多功能\r\n3.修复上个版本的Bug").setPositiveButton("确定", listener).setNegativeButton("取消", listener).setNeutralButton("稍后", listener).setCancelable(false).show();}
5.单选对话框
public void singleChoice(View v) {final String[] items = { "Java", ".Net", "C++", "PHP" };OnClickListener listener = new OnClickListener() {private int select;@Overridepublic void onClick(DialogInterface dialog, int which) {// TODO Auto-generated method stubswitch (which) {case DialogInterface.BUTTON_POSITIVE:Toast.makeText(getApplicationContext(), items[select],Toast.LENGTH_SHORT).show();break;default:select = which;break;}}};new Builder(this).setTitle("选择要学习的课程").setSingleChoiceItems(items, 0, listener).setPositiveButton("确定", listener).show();}
6.多选对话框
public void multiChoice(View v) {final String[] items = { "Java", ".Net", "C++" };final boolean[] selection = { false, false, false };OnMultiChoiceClickListener choiceListener = new OnMultiChoiceClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which,boolean ischecked) {// TODO Auto-generated method stub}};OnClickListener buttonListener = new OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {// TODO Auto-generated method stubStringBuilder sb = new StringBuilder();for (int i = 0; i < selection.length; i++) {if (selection[i]) {sb.append(items[i] + " ");}}Toast.makeText(getApplicationContext(), sb, Toast.LENGTH_SHORT).show();}};new Builder(this).setTitle("请选择要学习的课程").setMultiChoiceItems(items, selection, choiceListener).setPositiveButton("确定", buttonListener).show();}
7.进度对话框
public void progress(View v) {final ProgressDialog dialog = new ProgressDialog(this);dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);dialog.setTitle("下载中,请稍等....");dialog.setCancelable(false);dialog.setMax(200);dialog.show();new Thread() {public void run() {for (int i = 1; i <= 200; i++) {dialog.setProgress(i);try {Thread.sleep(20);} catch (Exception e) {// TODO: handle exception}}dialog.dismiss();}}.start();}
0 0
- android 常用对话框 ---转载
- 常用的Android对话框
- Android 常用代码---对话框
- 常用的android对话框
- Android 常用对话框
- Android中常用对话框
- 常用的android弹出对话框
- 常用的android弹出对话框
- 常用的android弹出对话框
- 常用的android弹出对话框
- 常用的android提示对话框
- 常用的android弹出对话框
- 常用的android弹出对话框
- 常用的android弹出对话框
- 常用的android弹出对话框
- 常用的android弹出对话框
- 常用的android弹出对话框
- 常用的android弹出对话框
- 关于变量,作用域与闭包;也再讨论一下C++0x的lambda表达式(预演……)
- Java中的泛型方法
- java集合: List、Set、Map总结 + HashMap/Hashtable 区别
- 2.1.19 Gray Code
- 获取鼠标点击的RGB
- Android 常用对话框
- 设计模式:浅析 抽象工厂、工厂方法、简单(静态)工厂 java实现
- asdasfsdfkskdfhkasd
- 第八章 8.3.2节练习
- 三闾大夫看见了sdk附近可谓分撒旦法
- poj 3693 Maximum repetition substring
- Android程序员必备精品资源
- 《星球大战》影评 转
- 发表文章