Hello Coder,
In this tutorial I will show you that how we can use custom layout in material toolbar layout. This is very easy just put your layout directly inside
<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" />
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);setSupportActionBar(toolbar);
<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>
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);setSupportActionBar(toolbar);ImageView logo = (ImageView) toolbar.findViewById(R.id.logo);TextView title = (TextView) toolbar.findViewById(R.id.title);
This way we can use custom layout inside Toolbar, like custom logo,icons, titles etc according to your need.
if you are getting extra margin from left in toolbar layout then read this post to Remove extra paddings from toolbar custom layout.
Quick Links
Legal Stuff
Social Media