1

I know you can reference an icon with

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

So this goes in the drawable folder and looks up the ic_config image.
But I recently saw this:

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

Now I don't understand how the mapping between my config-image and ?iconConfig is working, I can see that 'iconConfig' appears in the R.java and attr.xml files, but nowhere else.
Can anyone explain?

Willi Mentzel
  • 27,862
  • 20
  • 113
  • 121
user2870415
  • 41
  • 1
  • 7
  • 1
    This might help you http://stackoverflow.com/questions/21039310/difference-between-androidicon-drawable-my-icon-and-androidicon-my-icon – Lino Jan 03 '17 at 12:36

2 Answers2

0

'?' is used when you need to refer to the drawable while having several themes. It is made to simplify the logic when switching between themes and let the Android automatically decide which resource to use.

NickitaX
  • 352
  • 2
  • 14
0

Please go through the following link:

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

Edit

for your convenience i am posting the required part from link provided above:

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.

Android Geek
  • 8,956
  • 2
  • 21
  • 35