如何使隐藏/显示工具栏时,我们的滚动列表顶端,知道在工具栏视图中activity_main.xml中描述,但recyclerView在另一fragmet描述nomed Fragment_main.xml如何使隐藏/显示工具栏时,我们的滚动列表顶端
对不起,我的英语:)
如何使隐藏/显示工具栏时,我们的滚动列表顶端,知道在工具栏视图中activity_main.xml中描述,但recyclerView在另一fragmet描述nomed Fragment_main.xml如何使隐藏/显示工具栏时,我们的滚动列表顶端
对不起,我的英语:)
这是一种简单的。 只是把这个代码工具栏
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"/>
在这样做的魔力:app:layout_scrollFlags="scroll|enterAlways"
记得在你的XML添加应用程序调用xmlns:app="http://schemas.android.com/apk/res-auto"
检查本教程:https://guides.codepath.com/android/Handling-Scrolls-with-CoordinatorLayout
由于您的活动有其内容视图中的工具栏开始的片段,你可以随时从片段得到它保持。
MainActivity mainActivity = (MainActivity)getActivity();
我建议做它的方法在您的MainActivity:
public void showToolbar(boolean show) {
// If you have your toolbar as a private member of MainActivity
toolbar.setVisiblity(show ? View.VISIBLE : View.GONE);
// But you can also do this
if (show) {
getSupportActionBar().show();
}
else {
getSupportActionBar().hide();
}
}
然后当你真正想从你的片段隐藏它,叫它:
((MainActivity)getActivity()).showToolbar(false);
要使用户界面变得更加流畅,我推荐翻译它,而不是立即隐藏它。看看上面的答案在这里寻找灵感:
android lollipop toolbar: how to hide/show the toolbar while scrolling?
如果你不知道如何照顾时,实际上显示或通过滚动逻辑隐藏它,看看这个库,手柄很多关于你和也给出了例子:
使用下面的代码:
<android.support.design.widget.CoordinatorLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
...>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"/>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/rvToDoList"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</android.support.design.widget.CoordinatorLayout>
如果回收站View是另一片段,然后在下面的行添加到含有RecyclerView在此CoordinatorLayout视图。
app:layout_behavior="@string/appbar_scrolling_view_behavior"
必须使用CoordinatorLayout
。
getSupportActionBar()。隐藏() – has19