码迷,mamicode.com
首页 > 其他好文 > 详细

Notification 开发中碰到的问题

时间:2014-07-27 22:33:59      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:android   style   blog   color   使用   os   文件   io   

 

注:下面所指的低版本是指2.3及2.3以下版本)

1.如何取消掉通知栏上的通知

  (1)设置对应的flags,让用户点击既被消除:

notification.flags = FLAG_AUTO_CANCEL;

    (2) 通过手动消除某项或则全部通知

mNotificationMgr.cancle(NOTIFICATION_ID);//消除对应ID的通知

mNotificationMgr.cancleAll();//消除创建的所有通知


2.低版本中的部分方法已经被弃用的

 (1)Notification.Builder(this).getNotification()

 (2)mNotification.setLatestEventInfo(this, "title", "content", null);  

这些方法都已经被启用,虽然还有效果,可是不建议使用。所以开发过程中尽量使用NotificationCompat.Builder(this)的构建方法去创建一个通知类。


 

 

 3. 如果在高版本不会出错,而在2.3上面报了这个错误,通过开发文档中的以下知道你可以找打

 设置contentIntent,如果你点击没有意图,可以在赋值的的Intent中设置为new Intent()既可,切记contentIntent不能为空。

 

    public PendingIntent getDefalutIntent(int flags){
        PendingIntent pendingIntent= PendingIntent.getActivity(this, 1, new Intent(), flags);
        return pendingIntent;
    }

 


 

 

 

 

4.低版本中,自定义的通知栏中如果带有按钮,可能按钮点击事件会失灵

 

解决方法:看其它的应用,好像在低版本都会隐藏掉那些按钮,就是为了不影响用户体验,所以应该就这么解决,判断版本号在去决定是否现在按钮。

 

 

5.低版本中,自定义布局中的字体颜色看不清

 

 

由于2.3及之前版本,背景设是白色的那我们定义字体颜色为系统预设的颜色:

 

在资源的src/values目录中的style.xml文件中设置它标题和内容的样式为:

<?xml version="1.0" encoding="utf-8"?>  
<resources>  
  
    <style name="NotificationContent">  
        <item name="android:textColor">?android:attr/textColorPrimary</item>  
    </style>  
  
    <style name="NotificationTitle">  
        <item name="android:textColor">?android:attr/textColorPrimary</item>  
        <item name="android:textStyle">bold</item>  
    </style>  
  
</resources>

 

 

在2.3之后的版本中(即API >=9的版本中),在资源文件下的src/values-v9目录中的style.xml文件中设置它标题和内容的样式为:

<?xml version="1.0" encoding="utf-8"?>  
<resources>  
  
    <style name="NotificationContent" parent="android:TextAppearance.StatusBar.EventContent" />  
  
    <style name="NotificationTitle" parent="android:TextAppearance.StatusBar.EventContent.Title" />  
  
</resources>  

 

 

6.低版本中mBuilder.setProgress(100, progress, false);没用,不显示进度条

解决方法:此方法在4.0及以后版本才有用,如果为早期版本:需要自定义通知布局,其中包含ProgressBar视图

 

 

7.自定义布局的时候,不同版本方法不一样。(弄了半天,在2.3版本不显示,原来是方法不兼容)

2.3及2.3之前:

通过

    Notification notify = mBuilder.build();  
    notify.contentView = view_custom;  
    mNotificationManager.notify(notifyId, notify)  

 

 

方法赋予VIEW。

2.3之后:

 

通过Builder以下方法赋于自定义布局。

 

mBuilder.setContent(view_custom)

 


 

Notification 开发中碰到的问题,布布扣,bubuko.com

Notification 开发中碰到的问题

标签:android   style   blog   color   使用   os   文件   io   

原文地址:http://www.cnblogs.com/zhiqixue/p/3871499.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!