Search code examples
androidandroid-toolbar

Removing Padding between hamburger and Title


I would like to remove left padding in ActionBar between the hamburger & the title without having to use toolbars. I tried toolbars but i have encountered limitations that i felt were drawbacks. I am new in Android programming and would appreciate a clean solution to this using the default ActionBar.

enter image description here


Solution

  • try this use below property of toolbar

    app:contentInsetLeft="0dp"
    app:contentInsetStart="0dp"
    app:contentInsetStartWithNavigation="0dp"
    

    now set you toolbar like this

    <android.support.design.widget.CoordinatorLayout  xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     android:layout_width="match_parent"
     android:layout_height="match_parent">
    
     <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay"
            app:contentInsetLeft="0dp"
            app:contentInsetStart="0dp"
            app:contentInsetStartWithNavigation="0dp" />
    
     </android.support.design.widget.AppBarLayout>
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
    
        // add here all your controlls
    </LinearLayout>
    
    </android.support.design.widget.CoordinatorLayout>
    

    now set toolbar in activity like this

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
    

    ask me in case of any query