Search code examples
androidxmlheadertoolbarandroid-appbarlayout

Custom header layout with AppBarLayout and Toolbar


How to develop my custom header with Toolbar and AppBarLayout ?I want to add my own custom xml using this.

<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="?android:attr/actionBarSize"
android:supportsRtl="false"
app:popupTheme="@style/AppTheme.PopupOverlay">


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

Solution

  • try something like 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:layout_width="match_parent"
             android:id="@+id/toolbar"
             android:layout_height="?attr/actionBarSize"
             app:popupTheme="@style/AppTheme">
    
                <android.support.constraint.ConstraintLayout
        android:id="@+id/ConstraintContainer"
        android:layout_width="match_parent"
        android:orientation="vertical"
        android:background="@android:color/black"
        android:gravity="center"
        android:layout_height="wrap_content">
    
        <!--Whatever textview/imageview you want to insert-->
    
                </android.support.constraint.ConstraintLayout>
    </android.support.v7.widget.Toolbar>