Custom layout on toolbar with TabLayout below

I look normal now Toolbar

. I want to add a custom layout between Toolbar

and TabLayout

as shown in the image below:

enter image description here

The left is what now looks like mine Toolbar

, and the right is what I want it to look like.

As you can see, I want to add to the layout ImageView

and two TextView

.

How can I achieve this?

Here is my current layout:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        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"
            app:layout_collapseMode="pin"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

        <android.support.design.widget.TabLayout
            android:id="@+id/tablayout"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            app:layout_scrollFlags="scroll|enterAlways" />

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</android.support.design.widget.CoordinatorLayout>

      

+3


source to share


2 answers


AppBarLayout extends LinearLayout

, so you can add any number of views in AppBarLayout

: there is no reason to add views specifically for yours Toolbar

.



You want you to use the same layout_scrollFlags

as yours Toolbar

if you want them to scroll the same.

+1


source


The Toolbar is just a ViewGroup, you can customize as much as you like.

Try the following:

<android.support.v7.widget.Toolbar
 style="@style/ToolBarStyle"
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:background="?attr/colorPrimary"
 android:minHeight="@dimen/abc_action_bar_default_height_material">

<ImageView
    android:layout_width="wrap_content"
    android:contentDescription="@string/logo"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:src="@drawable/ic_launcher"/>

      



This should bring your ImageView to the center of the toolbar.

0


source







All Articles