I used the following hack to change the homeAsupIndicator programmatically.
int upId = Resources.getSystem().getIdentifier("up", "id", "android");
if (upId > 0) {
ImageView up = (ImageView) findViewById(upId);
up.setImageResource(R.drawable.ic_action_bar_menu);
up.setPadding(0, 0, 20, 0);
}
But this is not working on most new phones (HTC One, Galaxy S3, etc). Is there a way that can be changed uniformly across devices. I need it to be changed only on home screen. Other screens would have the default one. So cannot use the styles.xml
use
getActionBar().setCustomView(int yourView);
because ActionBar haven't method to change homeUp icon!The solution by checking
Resources.getSystem()
doesn't work on all devices, A better solution to change thehomeAsUpIndicator
is to set it @null in style and change the logo resource programmatically.Below is my code from style.xml
In code you can change the logo using
setLogo()
method.Also note that the
Android API 18
has methods to edit the homeAsUpIndicator programatically, refer documentation.API 18 has new methods
ActionBar.setHomeAsUpIndicator()
- unfortunately these aren't supported in the support library at this momenthttp://developer.android.com/reference/android/app/ActionBar.html#setHomeAsUpIndicator(android.graphics.drawable.Drawable)
edit: these are now supported by the support library http://developer.android.com/reference/android/support/v7/app/ActionBar.html#setHomeAsUpIndicator(android.graphics.drawable.Drawable)
This is what i did to acheive the behavior. I inherited the base theme and created a new theme to use it as a theme for the specific activity.
and in the android manifest i made the activity theme as the above.
works great. Will update again when i check on all devices I have. Thanks @faylon for pointing in the right direction
Adding to Fllo answer Change the actionbar homeAsUpIndicator Programamtically
I was able to use this hack on Android 4+ but could not understand why the up/home indicator was back to the default one when search widget was expanded. Looking at the view hierarchy, turns out that the up/home indicator + icon section of the action bar has 2 implementations and of course the first on is the one for when the search widget is not expanded. So here is the code I used to work around this and get the up/home indicator changed in both cases.