首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >android通知图标显示异常

android通知图标显示异常
EN

Stack Overflow用户
提问于 2018-09-14 12:18:13
回答 2查看 125关注 0票数 0

我的代码如下。通知显示在第一张图片中。当我向下拖动打开通知栏时,就像第二个一样。我想知道为什么会有一个显示得很好的大图标和右下角,还有一个白色的空白图标…

我该怎么纠正它呢?代码如下所示。

代码语言:javascript
复制
builder = new NotificationCompat.Builder(context);

mRemoteViews = new RemoteViews(context.getPackageName(), R.layout.notify);

final Intent intent = new Intent(context, MainActivity.class);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon);

builder.setAutoCancel(false);
builder.setSmallIcon(R.drawable.icon);
builder.setLargeIcon(largeIcon);
builder.setContentTitle(context.getString(R.string.app_name));
builder.setOngoing(true);
EN

回答 2

Stack Overflow用户

发布于 2018-09-14 12:37:24

我希望这对你有用。

代码语言:javascript
复制
Notification notification = new Notification.Builder(getApplicationContext())
                .setContentTitle(getString(R.string.app_name))
                .setContentText("Your Content Text")
                .setSmallIcon(getNotificationIcon())
                .setWhen(System.currentTimeMillis())
                .setContentIntent(contentIntent)
                .setAutoCancel(true)
                .build();

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

并确保您的图像背景应该是transparent.Version棒棒糖和以上的通知所需的透明背景图像。

票数 1
EN

Stack Overflow用户

发布于 2018-09-14 12:47:07

您用于通知的镜像无效/ android不支持。我认为你的问题是通知图标可能是多色的。理想情况下,图标应该是单色的。android状态栏只显示两种色调的图标,白色+彩色。你可以找到更多信息here

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52324916

复制
相关文章

相似问题

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