简体   繁体   中英

Android Where to place different icons for different themes?

In my application I have different Themes - one dark and one bright theme. Each theme requires his own icon set.

How do I apply it to the theme? Is there something like a special folder like for icons with different sizes ?

The following serves as a hint...

I suppose this may help: http://developer.android.com/reference/android/R.attr.html#icon

Lets say you have the following themes...

<style name="MyTheme.Dark">
  ...
</style>

<style name="MyTheme.Light">
  ...
</style>

You can add <item name="android:icon"></item> to each theme and supply each one with their own drawable icon. Then to get the respective drawables in your layout or what have you, you need to make use of ?android:attr/icon .

So your layout may end up looking something like...

<View
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:background="?android:attr/icon"/>

If you're unsure about what the ?android:attr/icon part exactly means, read http://developer.android.com/guide/topics/resources/accessing-resources.html#ReferencesToThemeAttributes .

Is there something like a special folder like for icons with different sizes ? (up to my knowledge) NO

no such default folder exist which you can use for Themes.

You need to do it programmatically.

Save the theme info in your Shared Preferences.

and at time of loading the view you can set your desired themed drawable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM