Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom home button on ActionBar

I am using ActionBar Sherlock library. So, to change the default home button. I did this:

<style name="Theme.mTheme" parent="android:Theme.Sherlock.Light.DarkActionBar">
    <item name="android:homeAsUpIndicator">@drawable/custom_home</item>
</style>

which didn't work

So, i added this too:

<item name="homeAsUpIndicator">@drawable/custom_home</item>

now its working. I am having this custom home icon/button on every ActionBar. But in 1 of my Activities i have this in code:

actionBar.setIcon(R.drawable.options_holo_dark);

When i am in that Activity, I can see the icon which i set programatically ie.., options_holo_dark. The 1 which i set in Theme ie.., custom_home is not visible. But the Icon has moved to the Right as if its giving space on the left to the icon i set in theme(though not visible).

This is what i am getting now:

enter image description here

So, how can i avoid that empty space on the left side of the Home Icon?

Thank You

like image 806
Archie.bpgc Avatar asked Dec 21 '12 10:12

Archie.bpgc


1 Answers

Theme item android:homeAsUpIndicator (and homeAsUpIndicator for ActionBarSherlock) sets drawable for the up icon - that's the little arrow pointing to left that is displayed next to the app icon when you have called setDisplayHomeAsUpEnabled(true) on the action bar.

The size of the up drawable defines the left margin for the app icon (logo). By default its dimensions are 16dp x 16dp. If you put there wider drawable the gap between edge of the screen and the app icon would be wider even though the up icon is not displayed at the moment.

If you want to change the app icon (logo). Use setLogo(int) or setLogo(Drawable) method of ActionBar. Don't forget to call setDisplayUseLogoEnabled(true) too - this method toggles between displaying app icon and custom logo. Also you can define the logo in manifest in attribute android:logo of <application> and <activity> tags and set in theme that you want to use logo instead of app icon in the action bar.

like image 156
Tomik Avatar answered Oct 02 '22 06:10

Tomik