Search code examples
androidandroid-toolbar

How to remove the gap between navigation icon and toolbar logo?


How can I remove the margin between the navigation icon and toolbar logo.

My toolbar layout

<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="@drawable/paper9patch"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:theme="@style/toolbarTheme"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp">

</android.support.v7.widget.Toolbar>

I am inserting logo like this

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

   toolbar.setContentInsetStartWithNavigation(0);
   getSupportActionBar().setDisplayShowTitleEnabled(false);
   getSupportActionBar().setLogo(R.drawable.sample);

my toolbar is looking like this

enter image description here

the logo is almost showing in the middle I want it beside the drawer icon

I searched on stackover flow and all answers tell to use

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

but its not working . I can say there is no padding for the image it is cropped exactly to edges. If i use tile there is no gap in middle ,the gap appears only when inserted logo.

enter image description here

Is this intended behavior ? Is there any thing else I can do to remove the gap?

Edit : styles i am using

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>

    </style>

   <style name="toolbarTheme" parent="AppTheme">

    <item name="android:textColorPrimary">@color/themeColor</item>
    <item name="android:textColorSecondary">@color/themeColor</item>

    </style>

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

Solution

  • The Problem was with the image , It did not had any extra space or padding at side but the image resolution was higher .

    Solution is :

    Just decrease the image resolution of logo and every thing should work normally.