简体   繁体   English

android通知栏(图标)显示不正确

[英]android notification bar (icon) show not correctly

Im currently working on my android music application project. 我目前正在从事我的android音乐应用程序项目。 And I'm facing the notification problem. 我正面临通知问题。

pic source: http://postimg.org/image/enticjvjl/ 图片来源: http//postimg.org/image/enticjvjl/

please open the link first, When the song is pressed, the song plays correctly,everything is ok. 请先打开链接,按下歌曲后,歌曲会正确播放,一切正常。 However, in the first pic,the icon in the left hand side is not scaled correctly, which cause the problem. 但是,在第一个图片中,左侧的图标未正确缩放,从而导致了问题。 And within 1 sec, the notification icon is shown correctly as we can see in the second pic (the first icon with yellow background is my application). 在1秒钟内,通知图标正确显示,如我们在第二张图片中所见(带有黄色背景的第一个图标是我的应用程序)。

Here is the code I'm using to create the notification bar. 这是我用来创建通知栏的代码。

    Bitmap largeIcon;
    largeIcon = BitmapFactory.decodeResource(this.getResources(), R.drawable.launcher);
    int height = (int) this.getResources().getDimension(android.R.dimen.notification_large_icon_height);
    int width = (int) this.getResources().getDimension(android.R.dimen.notification_large_icon_width);
    largeIcon = Bitmap.createScaledBitmap(largeIcon, height, width, false);

    builder.setContentIntent(pendInt)
      .setSmallIcon(R.drawable.launcher)
      .setLargeIcon(largeIcon)
      .setTicker(songTitle)
      .setOngoing(true)
      .setWhen(System.currentTimeMillis())
      .setContentTitle("Playing")
      .setContentText(songTitle);
    Notification not = builder.build();

    startForeground(NOTIFY_ID, not);

I believe your problem is that you don't scale an icon which you set in setSmallIcon method. 我相信您的问题是您不缩放在setSmallIcon方法中设置的图标。 Try setting same icon as in setLargeIcon method. 尝试设置与setLargeIcon方法相同的图标。 Or the other way around :) 或反过来:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM