简单的通知栏效果
来源:互联网 发布:淘宝儿童摇摆车扭扭车 编辑:程序博客网 时间:2024/05/21 07:48
很简单的一个小例子,当通知来了,获取通知的内容并显示在文本框中。
写了两个按钮,一个发送通知,一个是取消通知。
活动:
/** * 测试通知栏 */public class TestNotify extends Activity implements OnClickListener {private TextView notifyTxt;private Button notifyBtn;private Button cancleBtn;private NotificationManager nManager;private Notification notify;private String myMsg= "";@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.acy_notify);initView();// 创建通知notify = new Notification();// 通知管理器nManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);// 为通知设图标,该图标显示在状态栏notify.icon = R.drawable.ic_com_sina_weibo_sdk_logo;// 设置默认// notify.defaults=Notification.DEFAULT_ALL;// 设置声音notify.defaults = Notification.DEFAULT_SOUND;// 设置震动notify.defaults = Notification.DEFAULT_VIBRATE;// 设置闪光灯notify.defaults = Notification.DEFAULT_LIGHTS;}public void initView() {notifyTxt = (TextView) findViewById(R.id.tv_settxt);notifyBtn = (Button) findViewById(R.id.btn_notify);cancleBtn = (Button) findViewById(R.id.btn_cancel);notifyBtn.setOnClickListener(this);cancleBtn.setOnClickListener(this);}@Overridepublic void onClick(View v) {// TODO Auto-generated method stubif (v == notifyBtn) {myMsg="灰色尘埃";// 通知文本notify.tickerText =myMsg;Intent intent = new Intent(getApplicationContext(),TestNotify.class);PendingIntent conteIntent = PendingIntent.getActivity(getApplicationContext(), 100, intent, 0);notify.setLatestEventInfo(getApplicationContext(), "标题", myMsg, conteIntent);notify.flags = Notification.FLAG_AUTO_CANCEL;nManager.notify(100, notify);notifyTxt.setText(notify.tickerText);} else if (v == cancleBtn) {nManager.cancel(100);}}}
布局:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/tv_settxt" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="显示通知效果" /> <Button android:id="@+id/btn_notify" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="发送通知" /> <Button android:id="@+id/btn_cancel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="取消通知s" /></LinearLayout>
效果:
通知的图标是用的新浪的log,独家记忆是通知里面的内容,点击通知获取的通知内容,显示在文本中。
注意:
1.如果你想加入闪光灯,震动或者声音的效果,那么首先你得添加使用的权限:
<uses-permission android:name="android.permission.FLASHLIGHT"/> <uses-permission android:name="android.permission.VIBRATE"/>然后,你在添加效果,可以使用默认的也可以自定义。
默认
// 设置声音notify.defaults = Notification.DEFAULT_SOUND;// 设置震动notify.defaults = Notification.DEFAULT_VIBRATE;// 设置闪光灯notify.defaults = Notification.DEFAULT_LIGHTS;
2.标识:
LAG_AUTO_CANCEL 该通知能被状态栏的清除按钮给清除掉
FLAG_NO_CLEAR 该通知能被状态栏的清除按钮给清除掉
FLAG_ONGOING_EVENT 通知放置在正在运行
FLAG_INSISTENT 是否一直进行,比如音乐一直播放,知道用户响应
0 0
- 简单的通知栏效果
- android自定义通知栏的效果音
- 关于Activity缩小到通知栏,再点击通知栏启动的效果_QQ效果
- android -- 通知栏的简单应用
- Android简单的消息通知栏
- 覆盖statebar的通知效果
- android滚动通知的效果
- 通知的简单使用
- 简单的通知
- 通知的简单运用
- 简单的Android通知
- 通知的简单实现
- Unity类似手机通知栏的滑动效果
- 通知栏简单使用
- android 应用内通知,仿通知栏通知效果,通知Toast,悬浮窗
- iOS通知的简单使用
- Notification(通知)的简单使用
- 通知中心的简单使用
- 单链表的逆置问题
- bad class的问题
- 异常处理:No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer...org
- Sphinx做全站搜索你会了木有?
- LOAD DATA的使用
- 简单的通知栏效果
- Oracle10g32位升级到64位方法
- 百度Android SDK应用弹错Couldn’t load libBaiduMapSDK_vX_X_X错误解决
- swing右键菜单
- 这只是一个生活的新起点
- SQL数据库链接C#的Application
- cocos2dx3.x 类似 coverflow效果
- Hadoop1.1.2学习笔记(4)
- 把网站由.net4.0降级为.net3.5遇到的500.19错误