Android ActionBar Icon Visibility

Needed to put an icon in the action bar for a “refresh” action of an Android app.

Setting an icon is simple, in the Action class something like:


@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.my_menu, menu);
return super.onCreateOptionsMenu(menu);
}

Which  requires having the associated XML resource file defined for “my_menu.xml” in /res/menu folder. Something like:


<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/action_refresh"
android:icon="@drawable/ic_action_refresh"
android:title="@string/refresh"
android:showAsAction="always"
android:onClick="refresh"/>
</menu>

Nothing too complicated. But then need a nice icon for it. Luckily Google provides some nice set of action icons available (at this time) at: https://developer.android.com/design/downloads/index.html

Which has the “ic_action_refresh” icon referenced in the XML above. So the problem then. There are two themes. Holo Light and Holo Dark. Using either of these the refresh icon always looks disabled. Why? Where is a bunch of instructions if you go looking to tweak this and tweak that.

What I found is the problem is that both of these have a high transparency value (perfect way to make a disabled look if you think about it..). Luckily there is a separate set of icons called “unstyled” or something like that. Using the refresh icon from this set actually makes the icon look enabled.. Now that is was fun to “debug”, or not.

Why make such sets? I have no idea. Probably I am just missing some big idea in Android UI design. Well, as long as it works for me now..

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s