Toast,Dialog,PopupWindow,Notification
2015-09-04 17:21
393 查看
1.Toast 依赖应用而不以来Activity,一般用getAppliacationContent。
构造器一般传三个参数。可单独设置setText,可以传入富文本。setDuration,设置显示的时长。setGravity(Gravity.CENTER(LEFT等),X偏移量int,Y偏移量int),控制Toast的位置。
可以自己写Layout,自定义Toast,setView。
2.Dialog AlertDialog
A、最简单的dialog
AlertDialog.Builder builder=new AlertDialog.Builder(….this);
builder.setICon,setTitle,setMessage,setNegativeButton,setNeutralButton,setPositiveButton…….
AlertDialog dialog=builder.create(); dialog.show();
B、弹列表框
setItems(数据数组,new Dialog….Click)
C、弹单选框
setSingleChoiceItems(数据数组,0,new Dialog…Click) 0为默认选中的
D、弹多选框
setMultichoiceItems(数据数组,boolean数组,new Dialog…OnMultichoice….) boolean接受是否checked
E、自定义Dialog
Dialog dialog=new Dialog(Ma..this,可加style),setContentView,requestWindowFeature(Window.FEATURE.NOTITLE)去掉标题栏,
F、DatePickerDialog 构造器(..this,new …OnDateSetListener..,mCalendar.get(YEAR),MONTH,DAY),5参数
G、TimePickerDialog 构造器(…this,new OnTimeSetListener…,mCalendar.get(HOUR24小时制),MINUTE,true24小时制) 5参数
3.Drawable中加< shape corners可设置角的圆滑度,solid可设置背景色,stroke可设置边框颜色和宽度
4.Theme一般指整体及系统的主题,style指某一块(button,dialog等控件)的风格(color,padding,size等),将View的样式属性可写到sytle.xml中,在控件最后一行加style=@style….
5.PopupWindow 在某控件底部或..弹出框,必须自己写View
构造器(….this),setWidth(ViewGroup.LayoutParams.MATCH.PARENT),setHeight,setContentView,setFocusable,SetOutSideTouchable(设置点击其他位置后消失),showAsDropDown(控件)
6.onKeyDown方法,if(keycode==keyEvent.KEY….BACK)如果按下返回键,可进行自定义操作
7.Notification PendingIntent(持有Intent),也可以说Intent的包装,在特定时刻触发。而Intent是及时传送。先声明NotificationManager=…getSystemService(NOTIFACATION SERVICE)
旧版本:
新版本
8.自定义Notification
RemoteView 只可以加简单的控件,TextView,ImageView,ProgressBar
RmoteViews rv=new RemoteViews(getPackageName(),R.layout.自定义layout)
Notification.Builder.setContent(rv)
构造器一般传三个参数。可单独设置setText,可以传入富文本。setDuration,设置显示的时长。setGravity(Gravity.CENTER(LEFT等),X偏移量int,Y偏移量int),控制Toast的位置。
可以自己写Layout,自定义Toast,setView。
2.Dialog AlertDialog
A、最简单的dialog
AlertDialog.Builder builder=new AlertDialog.Builder(….this);
builder.setICon,setTitle,setMessage,setNegativeButton,setNeutralButton,setPositiveButton…….
AlertDialog dialog=builder.create(); dialog.show();
B、弹列表框
setItems(数据数组,new Dialog….Click)
C、弹单选框
setSingleChoiceItems(数据数组,0,new Dialog…Click) 0为默认选中的
D、弹多选框
setMultichoiceItems(数据数组,boolean数组,new Dialog…OnMultichoice….) boolean接受是否checked
E、自定义Dialog
Dialog dialog=new Dialog(Ma..this,可加style),setContentView,requestWindowFeature(Window.FEATURE.NOTITLE)去掉标题栏,
F、DatePickerDialog 构造器(..this,new …OnDateSetListener..,mCalendar.get(YEAR),MONTH,DAY),5参数
G、TimePickerDialog 构造器(…this,new OnTimeSetListener…,mCalendar.get(HOUR24小时制),MINUTE,true24小时制) 5参数
3.Drawable中加< shape corners可设置角的圆滑度,solid可设置背景色,stroke可设置边框颜色和宽度
4.Theme一般指整体及系统的主题,style指某一块(button,dialog等控件)的风格(color,padding,size等),将View的样式属性可写到sytle.xml中,在控件最后一行加style=@style….
5.PopupWindow 在某控件底部或..弹出框,必须自己写View
构造器(….this),setWidth(ViewGroup.LayoutParams.MATCH.PARENT),setHeight,setContentView,setFocusable,SetOutSideTouchable(设置点击其他位置后消失),showAsDropDown(控件)
6.onKeyDown方法,if(keycode==keyEvent.KEY….BACK)如果按下返回键,可进行自定义操作
7.Notification PendingIntent(持有Intent),也可以说Intent的包装,在特定时刻触发。而Intent是及时传送。先声明NotificationManager=…getSystemService(NOTIFACATION SERVICE)
旧版本:
Notification notification=new Notification();//初始化Notification notification.icon=R.mipmap.ic_launcher;//设置通知的图片 notification.tickerText="我是一个消息";//设置状态栏消息 notification.flags=Notification.FLAG_AUTO_CANCEL;//设置为可以取消通知 Intent intent=new Intent(getApplicationContext(),MainActivity.class); //设置Intent供PendingIntent持有 PendingIntent pendingIntent=PendingIntent.getActivity(getApplicationContext(), 1, intent, PendingIntent.FLAG_ONE_SHOT); //设置PendingIntent使用方式,Intent对象的包装 notification.setLatestEventInfo(getApplicationContext(),"我是标题","我是内容",pendingIntent); //设置通知的内容和PendingIntent notification.when=System.currentTimeMillis();//Calendar.getInstance().getTimeInMillis();设置触发时间 mNotificationManager.notify(1,notification);//通知管理器添加通知,id=1
新版本
Intent intent1=new Intent(getApplicationContext(),MainActivity.class); PendingIntent pendingIntent1=PendingIntent.getActivity(getApplicationContext(),1,intent1,PendingIntent.FLAG_ONE_SHOT); Notification notification1=new Notification.Builder(getApplicationContext()).setSmallIcon(R.mipmap.ic_launcher). setTicker("状态栏显示消息").setContentTitle("消息题目").setContentInfo("时间下面"). setContentText("我是内容").setWhen(System.currentTimeMillis()). setContentIntent(pendingIntent1).setAutoCancel(true).build(); mNotificationManager.notify(2,notification1);
8.自定义Notification
RemoteView 只可以加简单的控件,TextView,ImageView,ProgressBar
RmoteViews rv=new RemoteViews(getPackageName(),R.layout.自定义layout)
Notification.Builder.setContent(rv)
相关文章推荐
- Linux时区信息和修改
- linux入门教程(九) 文本编辑工具vim
- 解决因为google cdn无法访问导致无法打开stackoverflow等网站的方法
- Linux 文本行列转换
- CentOS 6.6编译安装Nginx1.6.2+MySQL5.6.21+PHP5.6.3
- 20150830 Linux系统管理 --磁盘管理与系统管理
- 创建一个能成功引导开机的小linux裸机-2015090401
- linux 命令 wget
- 使用目前hadoop内置的序列化类(不使用自定义序列化类),实现流量统计的功能
- Windows平台下Apache+Tomcat配置
- Linux之grub的运行机制及grub修复
- VMware CentOS Device eth0 does not seem to be present
- Linux root 用户使用 chrome
- linux服务器操作系统的选择
- Linux Makefile学习(二)
- 1.2 Apache配置
- 用CentOS 6.7 构建FTP服务器实例
- tomcat搭建成功后,无法进入管理页面的解决方法
- 最小化安装Centos7后的部署(个人)
- Linux程序编译速度提高方法