简体   繁体   English

如何使用 Image Asset Studio 添加参考材料图标(用于通知生成器)

[英]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:然后出现一个弹出窗口,开发人员指示说:

  1. In the Icon Type field, select Notification Icons.在图标类型字段中,select 通知图标。
  2. Select an Asset Type, and then specify the asset in the field underneath. Select 一个资产类型,然后在下面的字段中指定资产。 (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". (对于“剪贴画”字段,单击按钮(位于“剪贴画”字样的右侧)。单击“剪贴画”按钮后,您可以从大量图标中进行选择,然后单击“确定”。然后我更改了名称字段为“ic_text”。

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.

相关问题 如何设置Image Asset Studio生成的通知图标供Firebase使用? - How to set the Notification Icon generated by Image Asset Studio to be used by Firebase? 如何在Android中使用builder.addaction(icon,“ string”,pendingIntent)通知方法添加图片? - How to add image using builder.addaction(icon,“string”,pendingIntent) method of notification in android? 为什么使用 Android Asset Studio 生成的通知图标图像是全白的? - why the image for notification icon generated using Android Asset Studio is completely white? 在 android studio 中更改图像资产中的通知图标颜色 - changing notification icon color in image asset in android studio 如何在adroid studio中制作圆形方形图像资产图标 - How to make Round Squre Image Asset Icon in adroid studio 如何在应用栏中添加资产图像作为 Flutter 应用程序中的操作图标? - How to add asset image in app bar as an action icon in Flutter application? android studio 图像资产中的圆形启动器图标 - Round launcher icon in android studio image asset 高分辨率图标和图像资产工作室 - High res icon and image asset studio 创建 Android 图标的“添加图像资源”在哪里? - Where is the “Add Image Asset” to create an Android Icon? 如何在android studio中添加图标图像按钮 - How to add icon image button in android studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM