【Android知识点精讲】(13)Toast和Notification
来源:互联网 发布:铝合金型材批发 知乎 编辑:程序博客网 时间:2024/05/19 08:23
文章出处:http://blog.csdn.net/scarthr/article/details/42404505
一 Toast
1. 显示Toast
Toast的基本使用很简单:
Toast.makeText(this, "内容", Toast.LENGTH_SHORT).show();第一个参数传上下文对象。
2. 指定位置显示Toast
如何指定Toast显示的位置呢?
Toast toast = Toast.makeText(this, "内容", Toast.LENGTH_SHORT);toast.setGravity(Gravity.CENTER, 0, 0);toast.show();setGravity后两个参数是x和y轴的偏移量。
3. 自定义Toast
自定义显示Toast也非常简单:
Toast toast = Toast.makeText(this, "内容", Toast.LENGTH_SHORT);toast.setView(new ImageView(this));toast.show();用setView方法设置我们想要显示的内容就行了,值得注意的是,当setView执行过后,上面的makeText中的”内容“就不会显示了。
二 Notification
1. 概述
先来看一下Notification的组成:
1. 通知的标题
2. 通知大图标
3. 通知的内容
4. 通知的信息
5. 通知小图标(在通知未展开时,显示在屏幕的最左上方)
6. 通知的创建时间
还有一种是大的通知:
这种通知多了一个第7部分,通知详细信息,这部分可能是图片,也可能是文字。
2. 使用
创建显示Notification方法如下:
Builder builder = new NotificationCompat.Builder(this);// 指定小图标builder.setSmallIcon(R.drawable.ic_launcher);// 指定标题builder.setContentTitle("消息标题");// 指定消息的主体文字builder.setContentText("消息内容,很多文字");Notification notification = builder.build();NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);manager.notify(NOTIFICATION_ID, notification);指定小图标、指定标题和指定内容文字是创建Notification最少的3个条件。
0 0
- 【Android知识点精讲】(13)Toast和Notification
- Android-Toast和Notification
- Android中的Toast和Notification
- Android自定义Dialog,Toast,Notification和PopupWindow
- Android中的消息通知Toast和Notification
- Android中的消息通知Toast和Notification
- Android中的消息通知Toast和Notification
- Android Notification与Toast
- Toast和Notification
- 练习Toast和Notification
- Toast和Notification
- 自定义Notification和Toast
- Android第四讲——常用的基本控件(三)Toast、Dialog、PopupWindows、Notification(通知)、ViewPager
- android 消息提醒(Toast,Notification)
- Android Toast&Notification(Part I)
- Android Toast and Notification partII
- Android的Notification知识点
- Toast Notification
- Java高效排序大文件
- linux下无法识别u盘
- Linux下的/etc解释
- kickstart配置文件详解
- 自动寻径
- 【Android知识点精讲】(13)Toast和Notification
- 字符串Hash的原理与应用
- 代理模式@protocol
- hdu 3870 Catch the Theves 平面图转对偶图
- centos6.2桌面菜单的编辑和配置
- 《调试九法-软硬件错误的排查之道》
- 多路归并
- 内存山介绍和图解析
- csvkit 学习和使用 (四)