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"
<android.support.v7.widget.Toolbarandroid:id="@+id/toolbar"android:layout_width="match_parent"android:layout_height="?attr/actionBarSize"android:background="?attr/colorPrimary"app:popupTheme="@style/MenuTheme"><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"><ImageViewandroid:id="@+id/logo"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentLeft="true"android:layout_centerVertical="true"android:padding="8dp" /><TextViewandroid:id="@+id/title"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerInParent="true" /></RelativeLayout></android.support.v7.widget.Toolbar>
<android.support.v7.widget.Toolbarandroid: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"><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"><ImageViewandroid:id="@+id/logo"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentLeft="true"android:layout_centerVertical="true"android:padding="8dp" /><TextViewandroid:id="@+id/title"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerInParent="true" /></RelativeLayout></android.support.v7.widget.Toolbar>
Quick Links
Legal Stuff
Social Media