Search code examples
androidandroid-actionbarandroid-4.0-ice-cream-sandwichpreferenceactivityandroid-homebutton

setHomeButtonEnabled on PreferenceActivity and nested preference


I have preference screen extended PreferenceActivity. For targeting OS 4.0.3, I wanted to add < icon on action bar so I did this in onCreate().

ActionBar actionBar = getActionBar();
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);

It worked. < was added to left of app icon. But when I tap the item which goes into the next level (more detail screen), the < won't be displayed. Returning to the top level, the < appears again.

I have never thought about a mechanism of nested preference since smart the PreferenceActivity hides it. Now my question is, why won't PreferenceActivity display the < on nested preference?

I don't want to argue that I don't need to add < to the preference screen. (Even some of Google's app add, some don't, so I think there is no solid rule for this.)

If there is a simple solution for this, I want to solve this issue.


Solution

  • Instead of dynamically adding this, you should add the arrow by writing a custom ActionBar style to be used with your application theme. (Basically, see https://stackoverflow.com/a/16247111/582004)