我知道您可以使用
引用图标<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/