E
E
Evgeny Nizamiev2015-03-18 19:29:28
Android
Evgeny Nizamiev, 2015-03-18 19:29:28

How to deal with icons in different themes in the application?

The application has two themes: light and dark, but the icons were used only in light colors.
Icons are located in the actionbar and drop-down menus. In order for everything to be displayed adequately, I chose a background color on which they would "contrast", but when I started making applications in accordance with the material design, it turned out that the white icons were almost indistinguishable on the light drop-down menu.
What to do? how to proceed? Do you really have to somehow switch icons when changing the theme? Or is it possible to leave a "contrasting" background, and wouldn't that go against the rules of material design?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2015-03-26
@DrZ0idberg

This is done quite simply.
1) Create custom attributes for each image depending on the theme:

<declare-styleable name="AppTheme">
        <attr name="imageLogo" format="reference" />
</declare-styleable>

2) Add these attributes to your themes and specify the appropriate image option for each theme:
<style name="Theme" parent="@android:style/Theme.Holo.Light">
    <item name="attr/imageLogo">@drawable/logo_light</item>
</style>
<style name="Theme.Dark" parent="@android:style/Theme.Holo">
    <item name="attr/imageLogo">@drawable/logo_dark</item>
</style>

3) Use the theme attribute in the markup:
<ImageView
    …
    android:src="?attr/imageLogo"/>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question