一.Toast

//弹出吐司Toast.makeText(getApplicationContext(),"吐司",0).show();

二.对话框:
1.确定取消对话框

publicvoidclick1(Viewview){//对话框的创建器AlertDialog.Builderbuilder=newBuilder(this);builder.setTitle("我是对话框");builder.setMessage("对话框显示的内容");builder.setPositiveButton("确定",newOnClickListener(){@OverridepublicvoidonClick(DialogInterfacedialog,intwhich){Toast.makeText(getApplicationContext(),"确定被点击了",0).show();}});builder.setNegativeButton("取消",newOnClickListener(){@OverridepublicvoidonClick(DialogInterfacedialog,intwhich){//什么都不写默认实现就是关闭掉对话框}});builder.setCancelable(false);builder.create().show();}

2.单选对话框

publicvoidclick2(Viewview){//对话框的创建器AlertDialog.Builderbuilder=newBuilder(this);builder.setTitle("请选择您的性别");finalString[]items={"男","女","未知"};builder.setSingleChoiceItems(items,2,newOnClickListener(){@OverridepublicvoidonClick(DialogInterfacedialog,intwhich){Toast.makeText(getApplicationContext(),"您的性别:"+items[which],0).show();dialog.dismiss();}});builder.create().show();}

3.多选对话框

publicvoidclick3(Viewview){//对话框的创建器AlertDialog.Builderbuilder=newBuilder(this);builder.setTitle("请选择你最爱吃的水果");finalString[]items={"苹果","梨","菠萝","香蕉","黄瓜"};finalboolean[]result=newboolean[]{true,false,true,false,false};builder.setMultiChoiceItems(items,result,newOnMultiChoiceClickListener(){@OverridepublicvoidonClick(DialogInterfacedialog,intwhich,booleanisChecked){Toast.makeText(getApplicationContext(),items[which]+isChecked,0).show();result[which]=isChecked;}});builder.setPositiveButton("提交",newOnClickListener(){@OverridepublicvoidonClick(DialogInterfacedialog,intwhich){StringBuffersb=newStringBuffer();for(inti=0;i<result.length;i++){if(result[i]){sb.append(items[i]+",");}}Toast.makeText(getApplicationContext(),"您选中了,"+sb.toString(),0).show();}});builder.show();}

4.进度条对话框

publicvoidclick4(Viewview){ProgressDialogpd=newProgressDialog(this);pd.setTitle("提醒");pd.setMessage("正在加载数据...请稍等。");pd.show();}

5.带进度的进度条对话框

publicvoidclick5(Viewview){finalProgressDialogpd=newProgressDialog(this);pd.setTitle("提醒");pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);pd.setMax(100);pd.setMessage("正在加载数据...请稍等。");pd.show();newThread(){publicvoidrun(){for(inti=0;i<100;i++){try{Thread.sleep(40);}catch(InterruptedExceptione){e.printStackTrace();}pd.setProgress(i);}pd.dismiss();};}.start();}

三.notification----Android手机通知栏

//3.0以前的版本需要用过时的方法才行,否则报错publicvoidclick(Viewview){NotificationManagernm=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);Notificationnotification=newNotification(R.drawable.notification,"我是一个通知",System.currentTimeMillis());notification.flags=Notification.FLAG_AUTO_CANCEL;//点击后自动清除通知(Notification.FLAG_NO_CLEAR无法清除通知等等等)Intentintent=newIntent();intent.setAction(Intent.ACTION_CALL);intent.setData(Uri.parse("tel:119"));//向119拨打电话,要增加打电话的权限PendingIntentcontentIntent=PendingIntent.getActivity(this,0,intent,0);notification.setLatestEventInfo(this,"我是标题","我是内容",contentIntent);nm.notify(0,notification);}/***新版本的notification*@paramview*/@SuppressLint("NewApi")publicvoidclick2(Viewview){Notificationnoti=newNotification.Builder(this).setContentTitle("我是标题").setContentText("我是内容").setSmallIcon(R.drawable.notification).setLargeIcon(BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher)).build();NotificationManagernm=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);nm.notify(0,noti);}

更多相关文章

  1. Android(安卓)AlertDialog对话框详解及实例
  2. AndroidGUI14:各种Dialog常用技巧
  3. Android跳转到系统通知管理页面
  4. anroid studio更新中出现The Android(安卓)SDK folder can no lo
  5. 【简单的学生管理界面】Android添加简单的日历控件
  6. android线程间通信和主线程更新ui
  7. 【Android(安卓)开发教程】设置Activity的样式和主题
  8. android 组件之 alertDialog
  9. android对话框之AlertDialog.Builder类的setSingleChoiceItems

随机推荐

  1. 在什么语言中字符串以\0标志字符串的结
  2. 声明动态数组的语句怎么写
  3. 详解C++虚成员函数和动态联编
  4. c语言中文本输出的函数名称是什么?
  5. c语言函数声明格式是什么?
  6. c语言绝对值怎么表示
  7. c语言中逻辑运算符优先级是什么?
  8. 对比分析C#与Java的区别
  9. c语言中double是什么意思
  10. c语言fopen函数的用法