首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >通知中不显示图标:显示白色方块

通知中不显示图标:显示白色方块
EN

Stack Overflow用户
提问于 2018-04-20 08:13:53
回答 2查看 0关注 0票数 0

我的应用程序生成通知,但我为该通知设置的图标未显示。相反,我得到一个白色的广场。

我曾尝试调整图标的png(尺寸为720x720,66x66,44x44,22x22)。奇怪的是,当使用更小的尺寸时,白色方块更小。

我搜索了这个问题,以及生成通知的正确方式,并且从我读过的代码应该是正确的。可悲的是,事情并不像他们应该做的那样。

我的手机是Android 5.1.1的Nexus 5。问题也出现在模拟器上,Android 5.0.1版本的三星Galaxy S4以及Android 5.0.1版本的摩托罗拉Moto G(我都借用过,现在还没有)

通知代码如下,两个截图。如果您需要更多信息,请随时索取。

@SuppressLint("NewApi") private void sendNotification(String msg, String title, String link, Bundle bundle) { NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Intent resultIntent = new Intent(getApplicationContext(), MainActivity.class); resultIntent.putExtras(bundle); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, resultIntent, Intent.FLAG_ACTIVITY_NEW_TASK); Notification notification; Uri sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notificationsound); notification = new Notification.Builder(this) .setSmallIcon(R.drawable.lg_logo) .setContentTitle(title) .setStyle(new Notification.BigTextStyle().bigText(msg)) .setAutoCancel(true) .setContentText(msg) .setContentIntent(contentIntent) .setSound(sound) .build(); notificationManager.notify(0, notification); }

无需打开通知
无需打开通知

通知已打开
通知已打开
EN

回答 2

Stack Overflow用户

发布于 2018-04-20 17:06:55

原因:对于5.0“通知图标必须完全是白色的”。

如果我们通过将目标SDK设置为20来解决白色图标问题,我们的应用将不会针对Android棒棒糖,这意味着我们不能使用棒棒糖特有的功能。

目标Sdk 21的解决方案

如果你想支持棒棒糖素材图标,然后为棒棒糖和以上版本制作透明图标。请参阅以下内容:https//design.google.com/icons/

请查看http://developer.android.com/design/style/iconography.html,我们将看到白色风格是如何在Android Lollipop中显示通知。

谷歌还建议我们使用会显示在白色通知图标后面的颜色。请参阅链接:https//developer.android.com/about/versions/android-5.0-changes.html

无论我们想要添加颜色 https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#setColor(int)

对于低于和高于Lollipop操作系统版本的通知生成器的实现将是:

Notification notification = new NotificationCompat.Builder(this);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    notification.setSmallIcon(R.drawable.icon_transperent);
    notification.setColor(getResources().getColor(R.color.notification_color););
} else { 
    notification.setSmallIcon(R.drawable.icon);
} 

注意:setColor仅在棒棒糖中可用,并且仅影响图标的背景。

它会完全解决你的问题!

票数 0
EN

Stack Overflow用户

发布于 2018-04-20 18:10:17

我真的建议遵循Google的设计指南

“通知图标必须完全是白色的。”

以下是您可以如何实现它的方法:

如果您使用Gradle / Android Studio构建应用程序,请使用build.gradle:

defaultConfig {
    targetSdkVersion 20
}

否则(Eclipse等)使用AndroidManifest.xml:

<uses-sdk android:minSdkVersion="..." android:targetSdkVersion="20" />
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100003951

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档