0

I'm having trouble getting the .setSmallIcon(R.drawable.ic_name) attribute of the notification builder to recognize the material icon that I chose using Image Asset Studio in Android Studio. I can get it to work if I choose one that Android has already publicly declared (e.g. .setSmallIcon(R.drawable.ic_dialog_info).

The full Kotlin statement is (using the ic_dialog_info that is recognized):

val notification: Notification = NotificationCompat.Builder(this, CHANNEL_ID)
            .setContentTitle("Example service")
            .setContentText(input)
            .setSmallIcon(R.drawable.ic_dialog_info)
            .setContentIntent(pendingIntent)
            .build()

I've run Image Asset Studio (following these directions on the developers page) which told me to right click on the res folder and choose New->Image Asset.

Then a popup appears and the developer directions say to:

  1. In the Icon Type field, select Notification Icons.
  2. Select an Asset Type, and then specify the asset in the field underneath. (For the Clip Art field, click the button (which is to the right of the words "Clip Art"). Once you click the Clip Art button you can choose from a large selection of icons and then click ok. Then I changed the name field to "ic_text".

Here's what the popup looks like at this point: enter image description here

After clicking on "Next", I get the following popup with the chance to change the Icon path. Here's what that looks like:

enter image description here

I left the run directory path as is and clicked "Finish."

I get a subdirectory under drawable->ic_text with 5 ic_tet.png files as shown below:

enter image description here

When I type: .setSmallIcon(R.drawable.ic_
the autocomplete doesn't show my icon in the list.

I'm using Android Studio Bumblebee 2021.1.1

I do see the folders in the Project Files view:

enter image description here

Can someone tell me what I've missed? Why doesn't the new icon show up in the autocomplete list and what should I change?

Jim
  • 33
  • 10

1 Answers1

0

Ok after a bunch more poking around, I found that the autocomplete DID recognize my icon name in MainActivity.kt, but did not in my ExampleService.kt (which is a service class). At some point "import android.R" was added to the import list in ExampleService.kt. This kept R.drawable.ic_text from being found. Once I deleted the "import android.R" statement, autocomplete was able to find my icon. I'm still very new at this!

Jim
  • 33
  • 10