我添加了一个工具栏,我试图在工具栏滚动中使用隐藏和显示功能但由于某种原因它无法正常工作我从教程的每一步仍然无法正常工作。我在一个片段中使用工具栏,所以也许这是一个原因,但我不太了解它。 所以我会很感激一些帮助
XML
<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_content"
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">
<!-- AppBarLayout is a wrapper for a Toolbar in order to apply scrolling effects. -->
<!-- Note that AppBarLayout expects to be the first child nested within a CoordinatorLayout -->
<android.support.design.widget.AppBarLayout
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar">
<!-- Toolbar is the actual app bar with text and the action items -->
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:titleTextColor="@color/White"
app:layout_scrollFlags="scroll|enterAlways|snap">
<com.ct.listrtrial.Custom.CustomTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Feeds"
android:textSize="30sp"
android:textColor="@color/White"
android:layout_gravity="center"
android:id="@+id/toolbar_title"
android:layout_marginRight="@dimen/_200sdp"/>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<!-- This could also be included from another file using the include tag -->
<!-- i.e `res/layout/content_main.xml` -->
<!-- `app:layout_behavior` is set to a pre-defined standard scrolling behavior -->
<android.support.v7.widget.RecyclerView
android:id="@+id/feed_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchorGravity="bottom|center"
android:layout_marginBottom="5dp"
android:layout_gravity="end|bottom"
android:src="@drawable/ic_search_black_24dp" />
</android.support.design.widget.CoordinatorLayout>
片段代码
toolbar = (Toolbar)view.findViewById(R.id.toolbar);
((AppCompatActivity)getActivity()).setSupportActionBar(toolbar);
CustomTextView customTextView = (CustomTextView)toolbar.findViewById(R.id.toolbar_title);
//getActivity().getTitle();
((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(false);
答案 0 :(得分:0)
如果要在滚动时隐藏并显示工具栏,请将工具栏标记替换为。
app:layout_scrollFlags="scroll|enterAlwaysCollapsed|snap">
答案 1 :(得分:0)
在片段onCreateView
中添加以下代码ViewCompat.setNestedScrollingEnabled(recyclerView, true);
我认为这会对你有帮助。