转自:http://blog.youkuaiyun.com/u013624138/article/details/51437678
不同系统的通知背景色不同,使用自定义通知使用透明背景色,字体颜色跟随系统的Notification中文字的样式。
在res的values目录下定义styles.xml文件如下:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style
name="NotificationInfo"
parent="android:TextAppearance.StatusBar.EventContent" />
<style
name="NotificationTitle"
parent="android:TextAppearance.StatusBar.EventContent.Title" />
</resources>
在res的values-v21目录下定义styles.xml文件如下:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style
name="NotificationInfo"
parent="android:TextAppearance.Material.Notification.Info" />
<style
name="NotificationTitle"
parent="android:TextAppearance.Material.Notification.Title" />
</resources>
自定义通知布局文件调用:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/notification_title"
style="@style/NotificationTitle" />
<TextView
android:id="@+id/content_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/toast_ble_disconnected_1"
style="@style/NotificationInfo" />