Skip to content

Jacksgong/notification-adapter

Repository files navigation

Notification适配器

Notification风格适配,提取默认Notification的颜色

Download

编写这个的目的是目前还有好多应用自定义Notification的布局是hardcode的,导致在不同的系统主题中显得格格不入(如Wifi万能钥匙等),这个问题其实在2013年年底在微信就处理过,希望能够给大家带来思路。

辣眼睛案例

业界其实有很多很多Notification自定义布局并且hardcoard的案例,好不和谐....

解决方案

因此就是使用该工具获得Title与Text的颜色,然后保证背景是透明的,就可以解决该问题。

当然类似支付宝钱包这个Notification,我觉得是没有特别的必要自定义,此时更加推荐使用官方的Notification风格

使用

相关类: NotificationAdapter

Gradle引用:

dependencies {
    compile 'cn.dreamtobe.toolset:notification-adapter:1.0.0'
}

通过方法或者颜色

// 获取默认通知风格的Title的颜色
NotificationAdapter.getTitleColor(Context)
// 获取默认通知风格的Title的大小(Pixel)
NotificationAdapter.getTitleSize(Content)
// 获取默认通知风格的Text的颜色
NotificationAdapter.getTextColor(Context)
// 获取默认通知风格的Text的大小(Pixel)
NotificationAdapter.getTextSize(Content)
// 获取默认通知风格的Text的颜色

当然作为Notification,其实随着迭代演进已经有了很多很多很给力的Feature,也欢迎大家到Notification最佳实践拍砖,共同维护更好的Android环境。

验证

大家可以参考测试代码的使用来验证:

License

Copyright (C) 2017 Jacksgong(blog.dreamtobe.cn)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

The adapter for notification, what is used for adapter various system styles on notification

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages