[英]Hide Toolbar on scroll wont work properly [CoordinatorLayout]
I have a viewpager with 3 fragments which are using recyclerviews. 我有一个包含3个片段的viewpager正在使用recyclerviews。 I am trying to hide the toolbar when the user scrolls the recycled view. 当用户滚动循环视图时,我试图隐藏工具栏。 My problem is that the toolbar hides/shows when the user scrolls but it does not hide fully. 我的问题是当用户滚动时工具栏会隐藏/显示,但它不会完全隐藏。 I don't understand what I am doing wrong. 我不明白我做错了什么。 To illustrate what exactly is happening I am including two pictures with the two states of the toolbar (hidden and shown). 为了说明究竟发生了什么,我将工具栏的两个状态(隐藏和显示)包括两张图片。
NOTE: one thing that I noticed when the toolbar is hiding. 注意:工具栏隐藏时我注意到的一件事。 It does not go "under" the system status bar like it should but goes above it. 它不会像它应该“低于”系统状态栏,而是高于它。
As it can be seen, the toolbar is not fully hidden. 可以看出,工具栏未完全隐藏。 I can see parts of the Toolbar title and overflow icon at the right. 我可以在右侧看到工具栏标题和溢出图标的部分内容。
This is my main_layout xml: 这是我的main_layout xml:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:fab="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.studentsins.lust.MainActivity">
<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/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:layout_scrollFlags="scroll|enterAlways" />
<android.support.design.widget.TabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/NavigationTab"/>
</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"/>
<include layout="@layout/content_main"/>
<com.getbase.floatingactionbutton.FloatingActionsMenu
android:id="@+id/floatingActionMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
fab:fab_addButtonColorNormal="@color/blood_orange"
fab:fab_addButtonColorPressed="@color/dirtyWhite"
fab:fab_addButtonPlusIconColor="@color/dirtyWhite"
fab:fab_addButtonSize = "normal"
fab:fab_labelStyle="@style/menu_labels_style"
fab:fab_labelsPosition="left"
app:layout_anchor="@id/viewpager"
app:layout_anchorGravity="bottom|end">
<com.getbase.floatingactionbutton.FloatingActionButton
android:id="@+id/createPlanBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:fab_colorNormal="@color/blood_orange"
fab:fab_title="Create a plan"
fab:fab_size="normal"
app:fab_icon="@drawable/ic_event_white_48dp"
fab:fab_colorPressed="@color/dirtyWhite"/>
<com.getbase.floatingactionbutton.FloatingActionButton
android:id="@+id/changeStatusBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:fab_colorNormal="@color/blood_orange"
fab:fab_size="normal"
app:fab_icon="@drawable/ic_textsms_white_48dp"
fab:fab_title="Change status"
fab:fab_colorPressed="@color/dirtyWhite"/>
</com.getbase.floatingactionbutton.FloatingActionsMenu>
</android.support.design.widget.CoordinatorLayout>
Found a workarround to the problem. 找到了解决问题的方法。 in v21/Styles.xml 在v21 / Styles.xml中
I had to change the "android:statusBarColor" from "transperant" to any color. 我不得不将“android:statusBarColor”从“transperant”更改为任何颜色。
<resources>>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@color/tab_bg</item>
</style>
The overlap is occurring because your tabLayout height is greater than your toolbar height. 发生重叠是因为tabLayout高度大于工具栏高度。 You can fix it by setting the tabLayout height to: android:layout_height="?attr/actionBarSize"
您可以通过将tabLayout高度设置为: android:layout_height="?attr/actionBarSize"
actionBarSize”来修复它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.