2015-11-29 42 views
4

我遇到了一个问题,我的状态栏被推离我的工具栏。工具栏推开状态栏

我想要的功能是当用户向下滚动ListView时,工具栏消失在状态栏后面,这样只有选项卡可见,就像在WhatsApp和YouTube应用程序中一样。

为了达到这种效果,或者得到这个功能我用这条线:

app:layout_scrollFlags="scroll|enterAlways" 

到我android.support.v7.widget.Toolbar,但要知道,我以前说过,在状态栏变得被推开。

enter image description here

enter image description here

enter image description here

<?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" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/main_content" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context=".MainActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/appbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingTop="@dimen/appbar_padding_top" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <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:background="?attr/colorPrimary" 
      app:popupTheme="@style/AppTheme.PopupOverlay"> 

     </android.support.v7.widget.Toolbar> 

     <android.support.design.widget.TabLayout 
      android:id="@+id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

    </android.support.design.widget.AppBarLayout> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 


</android.support.design.widget.CoordinatorLayout> 

回答

2

我有同样的问题,并设法解决它。只需删除该行:

android:fitsSystemWindows="true" 

从协调器布局。您可以在ViewPager中的布局中进一步查看,但在顶层看来会导致该问题。

+0

当我试过这个解决方案时,状态栏变成半透明白色,还有什么更多的事情要做? –