【问题标题】:Android .setColor for Large Icon大图标的 Android .setColor
【发布时间】:2014-11-18 13:28:25
【问题描述】:

我想问有没有办法用.setColor from .setLargeIcon 设置通知的颜色? 因为只要我同时使用.setSmallIcon.setLargeIcon,我的颜色就会用于小图标。我想用大图标表示我的个人通知图标,并用小图标触发通知的应用程序图标。

例子:

Bitmap maintenanceIcon = BitmapFactory.decodeResource(getResources(),R.drawable.maintenance);
            Intent replacePumpIntent = new Intent(this, FoodListActivity.class);
            PendingIntent replacePumpPendingIntent =  PendingIntent.getActivity(this,0,replacePumpIntent, PendingIntent.FLAG_UPDATE_CURRENT);
            NotificationCompat.Builder maintenanceBuilder = new NotificationCompat.Builder(this)


                    .setLargeIcon(maintenanceIcon)
                    .setSmallIcon(R.drawable.app)
                    .setContentTitle("Maintenance: ")
                    .setColor(getResources().getColor(R.color.alertMaintenance))
                    .setContentText(Html.fromHtml(getString(R.string.alert_maintenance_message)))

                    .setLights(Color.YELLOW, 500 , 500)
                    .setVibrate(new long[] { 100, 250, 100, 250, 100, 250 })
                    .setPriority(0x00000001)
                    .setStyle(new NotificationCompat.BigTextStyle()
                            .bigText(Html.fromHtml(getString(R.string.alert_maintenance_message))))
                    .addAction(R.drawable.ic_arrow_right_black, getString(R.string.alert_maintenance_button_1),replacePumpPendingIntent );

            NotificationManager maintenanceNotificationManager =
                    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            maintenanceNotificationManager.notify(3, maintenanceBuilder.build());

【问题讨论】:

    标签: java android notifications icons android-5.0-lollipop


    【解决方案1】:

    据此:https://stackoverflow.com/a/27023679/327011

    同时拥有两者时,无法更改大图标背景。大图标不应该是透明的。

    【讨论】:

      【解决方案2】:

      这将帮助您从通知图标中删除灰色

       Notification notification = new NotificationCompat.Builder(context)
          .setSmallIcon(R.mipmap.ic_launcher)
          .setContentText("Simple description of something meaningful")
          .setContentTitle("Yo check this out")
          .setColor(context.getResources()
                  .getColor(R.color.brand_color))
          .build();
      
       NotificationManager manager  = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
      
       manager.notify(SINGLE_NOTIFICATION_ID, notification);
      
       brand_color is defined as #FF0066CC.
      

      Source

      【讨论】:

        【解决方案3】:

        您可以为大图标着色,然后设置为 NotificationBuilder。使用此函数为位图着色:

        fun Bitmap.tint(color: Int): Bitmap =
            Bitmap.createBitmap(this.width, this.height, Bitmap.Config.ARGB_8888).also { outBmp ->
                Canvas(outBmp).drawBitmap(
                    this, 0f, 0f,
                    Paint().apply {
                        this.colorFilter = PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN)
                    }
                )
            }
        

        然后:

            NotificationCompat.Builder(context)
                .setColor(yourColor)
                .setLargeIcon(maintenanceIcon.tint(yourColor))
                .setSmallIcon(R.drawable.app)
        

        在这种情况下,小图标和大图标将被着色为所需的颜色

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-05-07
          • 2014-05-16
          • 2016-07-02
          • 2016-04-19
          • 1970-01-01
          • 2011-09-24
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多