Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Actionbar logo padding left

The actionbar shows a space on the left side of the logo. This space is reserved for the upindicator i think.

I want to give this space a defined distance of 20dp for example.

How can i do this?

I can set the padding of the icon to 0, but that does not remove the space between the logo and the left side of the screen.

I tried to solve it by using a custom layout. But there is a little problem. Every time the activity launches, first the normal actionbar appears and then shows the custom layout.

This is how i show my custom view:

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_custom);
        // Set up the action bar.
        final ActionBar actionBar = getActionBar();
        //set custom actionbar
        actionBar.setDisplayShowCustomEnabled(true);
        actionBar.setCustomView(R.layout.actionbar);
        //Displays the custom design in the actionbar
        actionBar.setDisplayUseLogoEnabled(false);
        actionBar.setDisplayHomeAsUpEnabled(false);
        actionBar.setDisplayShowHomeEnabled(false);
        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    }

This is in my styles.xml:

        <!--Customize the actionbar-->
        <item name="android:windowActionBarOverlay">false</item>
        <item name="android:actionBarStyle">@style/MyActionBar</item>
        <item name="android:actionButtonStyle">@style/MyActionButton</item>

    </style>

    <style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
        <item name="android:background">@color/green2</item>
        <item name="android:icon">@drawable/app_icon_small</item>
        <!-- Support library compatibility -->

    </style>

    <style name="MyActionButton" parent="@android:style/Widget.Holo.Light.ActionButton">
        <item name="android:paddingRight">@dimen/padding_border</item>
        <item name="android:paddingLeft">@dimen/padding_border</item>
        <item name="android:src">@drawable/icon_plus</item>
        <!--<item name="android:minWidth">0dp</item>-->
        <!--<item name="android:paddingLeft">0dp</item>-->
        <!--<item name="android:paddingRight">15dp</item>-->
        <!-- Support library compatibility -->
    </style>

This is the layout of the custom view:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:gravity="center_vertical"
    android:background="@color/green2">
    <ImageView
        android:id="@+id/header"
        android:contentDescription="@string/app_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="@dimen/padding_border"
        android:paddingRight="@dimen/padding_border"
        android:src="@drawable/app_icon_small"/>

    <EditText
        android:id="@+id/et_actionbar_title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="YOLO"
        android:gravity ="center"
        android:textColor="@android:color/black"
        android:textStyle="bold"
        android:background="@android:color/transparent"
        />
</LinearLayout>
like image 404
BertLeonaers Avatar asked Mar 26 '14 10:03

BertLeonaers


1 Answers

You can create xml file(your_xml_file) in folder /res/drawable, like this:

<?xml version="1.0" encoding="UTF-8"?>
<layer-list
    xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:drawable="@drawable/menu_button"
        android:right="20dp"/>


</layer-list>

and add it to code:

<activity android:name=...
            android:logo="@drawable/your_xml_file" >
like image 101
user1755546 Avatar answered Sep 23 '22 20:09

user1755546