【发布时间】:2016-08-08 20:30:10
【问题描述】:
大家!我在活动中的 FrameLayout 容器中有一个片段,它具有导航抽屉。片段有 TabLayout。如您所见,问题是 活动的工具栏在片段的 TabLayout 上投下阴影。我不想将 TabLayout 放在活动的 AppBar 布局中,因为我无法从片段访问它,而且,我在其他任何地方都不需要该 TabLayout。
这是我的activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/mainNavigationView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
这是app_bar_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<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/loginToolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/mainFragmentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
这是fragment_by_day_schedule.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<android.support.design.widget.TabLayout
android:id="@+id/byDayTabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabBackground="?attr/colorPrimary"
app:tabMode="scrollable" />
<android.support.v4.view.ViewPager
android:id="@+id/byDayViewPager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
当我在 ViewPager 的片段中向上滚动列表时,我还希望工具栏隐藏
您有什么想法可以实现吗?
【问题讨论】:
-
是什么让你认为如果你把它放在工具栏里,你将无法从片段中访问标签布局?老实说,我认为在工具栏内包含选项卡是一种更好且更广泛理解的模式。也可以实现在viewpager上移时隐藏工具栏的效果。
-
再次检查我的答案。我更新了你的第二个问题。
标签: android android-fragments material-design android-toolbar android-tablayout