Search code examples
androidxmlandroid-viewpagertoolbarandroid-tablayout

How to place tab layout after toolbar?


I have a tablayout and a viewpager inside a fragment. i have two tabs in my tablayout. and a toolbar in my app_bar_main.xml. but when i run my app tablayout hides the toolbar. how it can be placed after toolbar? here is my code this is my app_bar_main.xml file

<?xml version="1.0" encoding="utf-8"?>

<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="?attr/actionBarSize"
        android:background="#CC0000"
        android:titleTextColor="@color/white"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

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

<FrameLayout
    android:id="@+id/fragment_containerlayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#FFFFFF"></FrameLayout>

this is my fragment design where i have placed a tab layout and a view pager

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.nayab.demotask.ContactsFragment"
xmlns:app="http://schemas.android.com/apk/res-auto">


<android.support.design.widget.TabLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/contactstablayot"
    android:layout_gravity="left|top"
    android:background="#000000"
    app:tabTextColor="@android:color/white"
    />

<android.support.v4.view.ViewPager
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/fragviewpager"
    android:layout_gravity="left|center_vertical"
    android:layout_marginTop="30dp"
    android:background="#e6f1f5"
    />

can somebody please help me out


Solution

  • Try to use app:layout_behavior="@string/appbar_scrolling_view_behavior" on your Framelayout.