我目前使用抽屉布局和TabLayout进行活动,就像this image上的活动一样。但是,我在实际显示标题标题方面遇到了问题,可以在here上看到。虽然我仍然可以向左或向右滑动以更改可见选项卡,但标签栏标题不会出现。
这是活动的.xml布局(为了您的信息,我在此布局的活动文件中使用AppCompatActivity):
<?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>
我用xml修改了一下,似乎无法显示标签标题的原因是因为我将TabLayout放在DrawerLayout中。但是,将DrawerLayout放在TabLayout之外会使每个选项卡页面的内容不显示。
有没有办法同时使用DrawerLayout和TabLayout并显示标签栏?
答案 0 :(得分:0)
将TabLayout
置于DrawerLayout
内应该没有问题,请检查the answers in this thread。
我在代码中发现的唯一问题是您的DrawerLayout
不是布局的根视图。使用此控件时,必须将其设计为root视图。