我对协调器布局有一些问题。我在 appBarLayout 中有带有父 CoordinatorLayout 的活动工具栏(我想让工具栏可隐藏),在 appBarLayout 和 viewPager 中有带有 tablayout 的片段。这是活动的 XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/gradient"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/toolbar_container"
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="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
</android.support.design.widget.AppBarLayout>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.design.widget.CoordinatorLayout>
它是片段的 XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/gradient"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
style="@style/MyCustomTabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabGravity="fill"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
现在,我遇到了工具栏在某处的情况。
如果我将活动中的协调器布局更改为线性布局,我会看到工具栏可见,但正如您可以想象的那样,没有隐藏选项。
实际上,我经常使用协调器布局:在视差和其他情况下隐藏和显示工具栏 - https://github.com/Iamtodor/toolbars,所以你可以肯定,我有点了解它是如何工作的:)
另外,我想要这个来源: - https://github.com/codepath/android_guides/wiki/Handling-Scrolls-with-CoordinatorLayout - https://github.com/codepath/android_guides/wiki/Using-the-App -ToolBar#using-toolbar-as-actionbar - https://github.com/chrisbanes/cheesesquare
但是,当 tablayout 存在于与工具栏相同的 appbarlayout 中时,所有示例都存在。
我该如何解决?