Android 自定义Notification字体颜色适配

本文介绍如何在Android应用中创建自定义的通知样式,包括定义透明背景及跟随系统样式的字体颜色。通过在不同版本资源文件中指定样式实现跨版本兼容。

转自: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" />
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值