Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing blank space next to App Logo (ActionBar Sherlock)

Can someone tell me how to eliminate the padding to the left of the app logo???

Here's what im talking about http://s9.postimage.org/ksxjpx1e7/Untitled.png

You can easily reproduce this even with ABS Demos, by adding to AndroidManifest.xml

android:logo="@drawable/icon"

I even tried editing abs__action_bar_home.xml directly but somehow that damned padding is still there.

<view xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    class="com.actionbarsherlock.internal.widget.ActionBarView$HomeView"
    android:background="#00ff00" >


    <ImageView
        android:id="@id/abs__home"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
    android:padding="0dip"
    android:layout_marginLeft="0dip"
        android:layout_marginBottom="@dimen/abs__action_bar_icon_vertical_padding"
        android:layout_marginRight="8dip"
        android:layout_marginTop="@dimen/abs__action_bar_icon_vertical_padding"
        android:adjustViewBounds="true"
        android:contentDescription="@null"
        android:scaleType="fitCenter" />

        <ImageView
        android:id="@id/abs__up"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|left"
        android:layout_marginRight="-8dip"
        android:contentDescription="@null"
        android:src="?attr/homeAsUpIndicator"
        android:visibility="gone"
        tools:ignore="ContentDescription" />


</view>
like image 261
user2001816 Avatar asked Feb 17 '23 18:02

user2001816


1 Answers

As one of the comments pointed out, the padding is reserved for the up icon. The padding is present even though the up icon is not being displayed (so that the logo doesn't move when you hide/show the up icon). Using action bar (and ActionBarSherlock) there are basically 2 ways how to remove the gap:

1.Remove the up icon
The size of the up icon affects the left padding, if you put there a bigger image than the arrow is, the gap will be bigger. If you remove it the gap will be gone. Beware that removing the up icon might not bring the exact looks you wish. Up icon and logo are partially overlapped (the up icon has negative right margin) so removing the up icon (it actually sets the image to nothing, does not affect the visibility) might cause that the logo is partially hidden behind the left edge of the screen.
To remove the up icon set android:homeAsUpIndicator to @null.

<style name="MyTheme" parent="@style/Theme.Sherlock">
    <item name="homeAsUpIndicator">@null</item>
    <item name="android:homeAsUpIndicator">@null</item>
</style>

2.Hide home layout and use custom view instead
This way it's more work, but you can affect the result better. You would need to put the icon and the title into the custom view. To hide the home layout and show custom, you have to set android:displayOptions in the action bar style. And then set the proper custom view in the code (you can set it in styles too, but that way it's buggy).

<style name="MyTheme" parent="@style/Theme.Sherlock">
    <item name="actionBarStyle">@style/MyActionBarStyle</item>
    <item name="android:actionBarStyle">@style/MyActionBarStyle</item>
</style>

<style name="MyActionBarStyle" parent="@style/Widget.Sherlock.ActionBar">
    <item name="displayOptions">showCustom</item>
    <item name="android:displayOptions">showCustom</item>
</style>
like image 157
Tomik Avatar answered Mar 02 '23 18:03

Tomik