1

I currently make an activity with Drawer Layout and TabLayout, just like the one on this image. However, I'm having problems with actually displaying the tab title, which can be seen over here. While I can still swipe left or right to change the visible tab, the tab bar titles don't appear.

Here's the .xml layout for the activity (for your information, I'm using AppCompatActivity in the activity file for this layout):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:app="http://schemas.android.com/apk/res-auto"
   android:orientation="vertical"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:minWidth="25px"
   android:minHeight="25px"
   android:background="@android:color/white">

<android.support.v7.widget.Toolbar
   android:id="@+id/toolBar"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:minHeight="?attr/actionBarSize"
   android:background="?attr/colorPrimary"
   app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
   app:popupTheme="@style/ThemeOverlay.AppCompat.Dark" />

<android.support.v4.widget.DrawerLayout
   android:id="@+id/drawerLayout"
   android:layout_width="match_parent"
   android:layout_height="match_parent">


<!-- The Main Content View -->
<android.support.design.widget.TabLayout
    android:id="@+id/request_tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:tabMode="fixed"
    app:tabGravity="fill"
    android:background="@color/colorPrimary" />
<android.support.v4.view.ViewPager
      android:id="@+id/viewpager"
      android:layout_width="match_parent"
      android:layout_height="0px"
      android:layout_weight="1"
      android:background="@android:color/white" />  

<!-- The Left Navigation Drawer -->
    <ListView
        android:id="@+id/leftDrawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="#818181"
        android:dividerHeight="2dp"
        android:background="#E3F2FD" />

</android.support.v4.widget.DrawerLayout>

</LinearLayout>

I tinkered around a bit with the xml, and it appeared that the reason why the tab title couldn't be displayed is because I put the TabLayout inside DrawerLayout. However, putting the DrawerLayout outside of TabLayout makes the content of each tabbed page don't appear.

Is there any way to use both DrawerLayout and TabLayout and make the tab title bar appear?

Astral
  • 11
  • 3

1 Answers1

0

There should be no problem to put a TabLayout inside a DrawerLayout, check the answers in this thread.

The only problem I found with your code is that your DrawerLayout is not the root view of your layout. When using this control, it must be designed as root view.

Community
  • 1
  • 1
Grace Feng
  • 16,564
  • 2
  • 22
  • 45