I usually set drawable in xml as android:icon="@drawable/my_icon"
But in some projects I see the code android:icon="?my_icon"
.
What's the difference between android:icon="@drawable/my_icon"
and android:icon="?my_icon"
?
Pointing to this document and referencing the answer from there: Applying styles and themes
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.
Lets take an example declaration of a theme defined on the link:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomTheme">
<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). (E.g., panelTextColor uses the same color assigned to panelForegroundColor, defined beforehand.) This technique can be used only in XML resources.
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.
So, if you see that menuItemTextColor
point to another item panelTextColor
which again has question mark in front of its value. Why? Because we are again referencing a resource value from the currently loaded customTheme
.
Similarly although you haven't mentioned any code but its possible that the currently loaded theme has item
called my_icon
whose value references a resource value pointing to some drawable in the project.
Hope this clears you a bit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With