Reputation: 23394
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
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.
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" />
Upvotes: 0
Views: 1961
Reputation: 23394
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.
Upvotes: 1
Reputation: 21043
Try this although it not much different from your layout but its works well i have tested it .
<android.support.design.widget.CoordinatorLayout
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/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:contentInsetLeft="0dp"
android:contentInsetStart="0dp"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp"
android:gravity="center"
app:popupTheme="@style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
Set up toobar as.
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("New");
getSupportActionBar().setLogo(R.mipmap.ic_launcher);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Upvotes: 1
Reputation: 69689
Try this
<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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@mipmap/ic_launcher_round" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
Upvotes: 1