[英]How to add a reference a material icon (for a notification builder) using Image Asset Studio
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.我无法让通知生成器的 .setSmallIcon(R.drawable.ic_name) 属性识别我在 Android Studio 中使用 Image Asset Studio 选择的材质图标。 I can get it to work if I choose one that Android has already publicly declared (eg .setSmallIcon(R.drawable.ic_dialog_info).
如果我选择 Android 已经公开声明的一个(例如 .setSmallIcon(R.drawable.ic_dialog_info)),我可以让它工作。
The full Kotlin statement is (using the ic_dialog_info that is recognized):完整的 Kotlin 语句是(使用识别的 ic_dialog_info):
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.我已经运行了 Image Asset Studio(按照开发人员页面上的这些说明),它告诉我右键单击 res 文件夹并选择 New->Image Asset。
Then a popup appears and the developer directions say to:然后出现一个弹出窗口,开发人员指示说:
Here's what the popup looks like at this point:这是弹出窗口此时的样子:
After clicking on "Next", I get the following popup with the chance to change the Icon path.单击“下一步”后,我得到以下弹出窗口,有机会更改图标路径。 Here's what that looks like:
看起来是这样的:
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:我在 drawable->ic_text 下获得了一个子目录,其中包含 5 个 ic_tet.png 文件,如下所示:
When I type: .setSmallIcon(R.drawable.ic_当我输入: .setSmallIcon(R.drawable.ic_
the autocomplete doesn't show my icon in the list.自动完成不会在列表中显示我的图标。
I'm using Android Studio Bumblebee 2021.1.1我正在使用 Android Studio Bumblebee 2021.1.1
I do see the folders in the Project Files view:我确实在项目文件视图中看到了文件夹:
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?
为什么新图标没有出现在自动完成列表中,我应该更改什么?
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).好吧,经过一番摸索,我发现自动完成功能确实识别出我在 MainActivity.kt 中的图标名称,但在我的 ExampleService.kt (这是一个服务类)中没有识别出我的图标名称。 At some point "import android.R" was added to the import list in ExampleService.kt.
在某些时候,“import android.R”被添加到 ExampleService.kt 的导入列表中。 This kept R.drawable.ic_text from being found.
这使 R.drawable.ic_text 无法被发现。 Once I deleted the "import android.R" statement, autocomplete was able to find my icon.
一旦我删除了“import android.R”语句,自动完成就能找到我的图标。 I'm still very new at this!
我对此还是很陌生!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.