java - 在 Android 应用程序中引用图标的方法

标签 java android icons

我知道您可以使用

引用图标
<item   android:id="@+id/config"
    android:icon="@drawable/ic_config"
    android:title="@string/config"
    app:showAsAction="ifRoom"/>

因此,这将进入可绘制文件夹并查找 ic_config 图像。
但我最近看到了这个:

    android:id="@+id/config"
    android:icon="?iconConfig"
    android:title="@string/config"
    app:showAsAction="ifRoom"/>

现在我不明白我的 config-image 和 ?iconConfig 之间的映射是如何工作的,我可以看到“iconConfig”出现在 R.java 和 attr.xml 文件中,但没有出现在其他地方。
谁能解释一下吗?

最佳答案

请访问以下链接:

http://www.linuxtopia.org/online_books/android/devguide/guide/topics/ui/themes.html

编辑

为了您的方便,我从上面提供的链接发布了所需的部分:

Just like styles, themes are also declared in XML elements, and are referenced in the same manner. The difference is that you add a theme to an entire application or activity, via the and elements in the Android Manifest — themes cannot be applied to individual Views.

Here's an example declaration of a theme:

<?xml version="1.0" encoding="utf-8"?> <resources>   <style name="CustomTheme">        
    <item name="android:windowNoTitle">true</item>
    <item name="windowFrame">@drawable/screen_frame</item>
    <item name="windowBackground">@drawable/screen_background_white</item>
    <item name="panelForegroundColor">#FF000000</item>
    <item name="panelBackgroundColor">#FFFFFFFF</item>
    <item name="panelTextColor">?panelForegroundColor</item>
    <item name="panelTextSize">14</item>
    <item name="menuItemTextColor">?panelTextColor</item>
    <item name="menuItemTextSize">?panelTextSize</item>   </style> </resources> 

Notice the use of the at-symbol (@) and the question-mark (?) to reference resources. The at-symbol indicates that we're referencing a resource previously defined elsewhere (which may be from this project or from the Android framework). The question-mark indicates that we're referencing a resource value in the currently loaded theme. This is done by referring to a specific by its name value. (E.g., panelTextColor uses the same color assigned to panelForegroundColor, defined beforehand.) This technique can be used only in XML resources.

关于java - 在 Android 应用程序中引用图标的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41443608/

相关文章:

android - 如何在android中检索联系人列表

Android 设备偶尔会重启

Android 仪表板图标大小

Java 负向前瞻排除单词

java - 修改服务层Spring data Page<>类投影响应

java - 如何根据嵌套对象属性对列表进行排序

android - firebase规则,android,硬编码将凭据写入应用程序,因此无需登录

react-native - React Native 使用 Expo 没有正确显示图标 [ (X) 和 ? ]

java - 如何从JDialog中完全删除图标?

java - 可以从样本表中读取,但现在可以从自己的表中读取