2

In my application I used icons in custom notification. The icons' color is black. It works fine in light mode, but NOT in dark. The icons are made by vector graphics in Android. The problem with the text is solve by

style="@style/TextAppearance.Compat.Notification.Title" 

in TextView. How can I use these icons for both Light and Dark Themes?

My Target & Compiling SDK is 30 Minimum Support SDK is 16

Vega
  • 27,856
  • 27
  • 95
  • 103
Riskhan
  • 4,434
  • 12
  • 50
  • 76

2 Answers2

0

You have to use icons in white color having transparent background. It will work for both light and dark theme. You can also change that white colour according to your app theme by adding some line of code as follows like gmail does:

For below Oreo:
  NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext(), getString(R.string.app_name))
            .setColor(ContextCompat.getColor(this, R.color.colorPrimary))

For above oreo:

     NotificationChannel mChannel = new NotificationChannel(channel_id, channel_name, noti_importance);
      mChannel.setLightColor(getColor(R.color.colorPrimary));
0

The only way to support light and dark themes on all versions of android is to use vector icons instead of bitmaps. Only in this case the system will apply colors to your icon to make them stand out against a light or dark background.
You have to make a transparent background for your icon, convert it to png format, and then convert it to svg format using any free converter. Android Studio supports converting from svg to standard xml format, so adding such an icon to a project shouldn't be a problem.
However, if the image has a complex shape, you should prepare the vector icon from scratch.
Another important note: in the case of using a vector icon, it must be monochrome (only one color is used). This is Material Design requirement: https://material.io/design/platform-guidance/android-notifications.html

Vega
  • 27,856
  • 27
  • 95
  • 103