Search code examples
androidandroid-toolbar

Reduce space between app logo and app name on action bar in android


I have action bar along with app logo and app name. So I want to reduce space between app logo and app name. Below I have attached some screenshot.

A) Action bar I have

enter image description here

B) Action bar I want

enter image description here


Solution

  • Use Toolbar for this, it will provide greater customization.

    Here is the sample example.

    toolbar.xml

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.v7.widget.Toolbar
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:layout_scrollFlags="scroll|enterAlways"
        app:layout_collapseMode="pin">
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    
            <!-- This is a centered logo -->
            <ImageView
                android:id="@+id/toolbar_logo"
                android:src="@drawable/logo"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_marginRight="?attr/actionBarSize"
                android:layout_marginTop="4dp"
                android:layout_marginBottom="4dp"
                android:layout_gravity="center" />
    
            <!-- This is a centered title -->
            <!--
            <TextView
                android:id="@+id/toolbar_title"
                android:orientation="horizontal"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_marginRight="?attr/actionBarSize"
                android:layout_gravity="center"
                android:gravity="center_vertical"
                android:visibility="gone"
                android:text="@string/app_name"
                android:textColor="@color/white"
                style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title.Inverse"
                />
                -->
    
            <!-- This is a custom left side button -->
            <!--
            <ImageButton
                android:id="@+id/btn_settings"
                android:layout_width="?attr/actionBarSize"
                android:layout_height="?attr/actionBarSize"
                android:layout_marginRight="?attr/actionBarSize"
                android:layout_gravity="start|center_vertical"
                android:visibility="invisible"
                android:src="@drawable/ic_settings_white_24dp"
                style="@style/Widget.AppCompat.ActionButton" />
                -->
    
            <!-- This is a custom right side button -->
            <!--
            <ImageButton
                android:id="@+id/btn_search"
                android:layout_width="?attr/actionBarSize"
                android:layout_height="?attr/actionBarSize"
                android:layout_gravity="end"
                android:src="@drawable/ic_magnify_white_24dp"
                style="@style/Widget.AppCompat.ActionButton" />
                -->
    
        </FrameLayout>
    </android.support.v7.widget.Toolbar>
    

    Add any view inside toolbar as it is a viewgroup. Hopw this helps