Learn Pain Less

HomeOur TeamContact
Android
Remove extra margins from Toolbar custom layout Android
Pawneshwer Gupta
Pawneshwer Gupta
December 31, 2016
1 min

Table Of Contents

01
Remove extra margins from Toolbar custom layout Android
02
Below is proper example:
Remove extra margins from Toolbar custom layout Android

Remove extra margins from Toolbar custom layout Android

In last post I showed that how we can use custom layout with toolbar. But in that post there is some extra left padding in toolbar and your layout not showing properly. Actually that is default inset used by toolbar layout. You can solve this problem by giving negative padding or margin to your layout but that is not accurate solution. So the best solution is to set Inset from all corners to 0dp. Below is example to set 0dp inset from all corners in toolbar layout.

so add these properties in <Toolbar />

android:contentInsetLeft="0dp"
android:contentInsetStart="0dp"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
android:contentInsetRight="0dp"
android:contentInsetEnd="0dp"
app:contentInsetRight="0dp"
app:contentInsetEnd="0dp"

Below is proper example:

old code :

<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/MenuTheme">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:padding="8dp" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>

new code :

<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"
android:contentInsetRight="0dp"
android:contentInsetEnd="0dp"
app:contentInsetRight="0dp"
app:contentInsetEnd="0dp"
app:popupTheme="@style/MenuTheme">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:padding="8dp" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>

Subscribe to our newsletter!

We'll send you the best of our blog just once a month. We promise.

Tags

toolbarappbarmaterial

Share


Pawneshwer Gupta

Pawneshwer Gupta

Software Developer

Pawneshwer Gupta works as a software engineer who is enthusiastic in creating efficient and innovative software solutions.

Expertise

Python
Flutter
Laravel
NodeJS

Social Media

Related Posts

how to make fully Android Transparent Status bar
how to make fully Android Transparent Status bar
January 10, 2018
1 min
Learn Pain Less  © 2024, All Rights Reserved.
Crafted with by Prolong Services

Quick Links

Advertise with usAbout UsContact Us

Social Media