当涉及到以下非常常见的设置时,我正在寻找最佳实践:
我目前正在做的是:
我的主要 Activity 有一个抽屉导航和一个工具栏。 当您单击抽屉内的列表项之一时,将在工具栏下方加载一个 fragment 。一些 fragment 使用 viewpager 等在内部有自己的选项卡。
我想利用 Material 功能,例如在滚动时隐藏工具栏等。完成它是没有问题的。 但是当只有一些 fragment 想要使用滚动工具栏时就会出现问题。如果您可以在底部添加额外的边距,使用普通的 Scrollview 确实可以解决问题,但是一旦您有了键盘,它就会因为滚动错误而变得困惑。使用 nestedscrollview 可以工作,但会滚动工具栏。 那么,当我的 Activity 持有工具栏时,我该如何避免滚动工具栏,并且一些滚动的 fragment 应该使用它而有些则不需要?
是不是架构设计错了?我想的另一件事是在每个 fragment 中有不同的工具栏......但是它们必须共享同一个抽屉导航所以你必须每次都创建和添加 ToggleButton?这是正确的方法吗?我应该走那条路吗?我不相信并且想听听比我更有经验的人的意见。在这种情况下最好的解决方案是什么。
感谢您的帮助! 干杯
编辑: 主要 Activity
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/fragment_container_first"
>
<android.support.design.widget.AppBarLayout
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:id="@+id/owner_main_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/appBar"
android:orientation="horizontal"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/addicon"
app:fabSize="normal"
app:layout_anchor="@id/owner_main_container"
app:layout_anchorGravity="bottom|right|end"
app:layout_behavior="xxx.Classes.Misc.ScrollAwareFABBehavior"
/>
</android.support.design.widget.CoordinatorLayout>
<!-- The navigation drawer -->
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="@menu/drawerhost" />
最佳答案
我也在使用抽屉导航和工具栏,请从 this link 导入项目 并尝试了解如何使用 fragment 使用抽屉导航和工具栏
关于android - 将 Activity 与抽屉、滚动工具栏、选项卡和不同的 fragment 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33007259/