Android 那些年踩过的坑

本文提供了一种方法,在不降低目标SDK版本的情况下解决Android Lollipop通知栏小图标变白的问题,通过使用轮廓图标并在设备运行Android Lollipop时显示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. Notification bar icon turns white in Android 5 Lollipop

http://stackoverflow.com/questions/28387602/notification-bar-icon-turns-white-in-android-5-lollipop

I have an app showing custom notifications. The problem is that when running in Android 5 the small icon in the Notification bar shows white. How can I fix this?

The accepted answer is not (entirely) correct. Sure, it makes notification icons show in color, but does so with a BIG drawback - by setting the target SDK to lower than Android Lollipop!

If you solve your white icon problem by setting your target SDK to 20, as suggested, your app will not target Android Lollipop, which means that you cannot use Lollipop-specific features.

Have a look at http://developer.android.com/design/style/iconography.html, and you'll see that the white style is how notifications are meant to be displayed in Android Lollipop.

In Lollipop, Google also suggest that you use a color that will be displayed behind the (white) notification icon - https://developer.android.com/about/versions/android-5.0-changes.html

So, I think that a better solution is to add a silhouette icon to the app and use it if the device is running Android Lollipop.

For instance:

Notification notification = new Notification.Builder(context) .setAutoCancel(true) .setContentTitle("My notification") .setContentText("Look, white in Lollipop, else color!") .setSmallIcon(getNotificationIcon()) .build(); return notification;

And, in the getNotificationIcon method:

private int getNotificationIcon() { boolean whiteIcon = (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP); return whiteIcon ? R.drawable.icon_silhouette : R.drawable.ic_launcher; }


转载于:https://www.cnblogs.com/lotusJade/p/4863802.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值