2015-11-30 40 views
17

Tôi đang gặp sự cố khi sử dụng Bố cục điều phối có chứa một AppBarLayout (giữ một thanh công cụ và tabLayout) và ViewPager (giữ đoạn) như trẻ em. Tôi muốn thanh đầu bị ẩn khi cuộn xuống và tiết lộ khi cuộn lại. Tuy nhiên khi tôi cuộn xuống, thanh trạng thái cũng cuộn lên, để thanh trên cùng ngay bên dưới các biểu tượng trạng thái, bị chồng chéo lên nhau.Thanh trạng thái Android cuộn lên với bố trí điều phối, để lại các biểu tượng trạng thái chồng chéo thanh công cụ tiêu đề

Tôi đã thử thêm android: fitsSystemWindows = "true" vào cả AppBarLayout và ViewPager nhưng không có gì thay đổi.

Bên dưới mã được sử dụng và ảnh chụp nhanh cho thấy hai trạng thái:

<android.support.design.widget.CoordinatorLayout 
    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" 
    android:fitsSystemWindows="true"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:layout_scrollFlags="scroll|enterAlways" 
      app:popupTheme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/> 

     <android.support.design.widget.TabLayout 
      android:id="@+id/sliding_tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      app:tabMaxWidth="0dp" 
      app:tabGravity="fill" 
      app:tabMode="fixed"/> 

    </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"/> 

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

Status Bar without scroll applied

Status Bar with scroll applied

+1

tôi đã cùng một vấn đề chính xác này, và tôi đã có thể giải quyết nó, nhưng tôi không có mã với tôi! Một vài khả năng: a) 'fitsSystemWindows =" true "' trên 'AppBarLayout', b) Thêm' contentScrim' vào 'AppBarLayout' hoặc' Thanh công cụ' của bạn ('app: contentScrim =" @ color/primaryDark "'), hoặc c) thử 'CollapsingToolbarLayout' thay vì' AppBarLayout', nhưng không cho nó sụp đổ cờ cuộn. Hy vọng một trong những giúp! –

Trả lời

30

Xem lại chủ đề cho hoạt động này, nếu chủ đề là như @ style/AppTheme.NoActionBar hoặc một chủ đề không có ActionBar, hãy thử đặt màu, bạn phải có kiểu (v21) như sau:

<style name="AppTheme.NoActionBar"> 
    <item name="windowActionBar">false</item> 
    <item name="windowNoTitle">true</item> 
    <item name="android:windowDrawsSystemBarBackgrounds">true</item> 
    <item name="android:statusBarColor">@android:color/transparent</item>  
</style> 

thay đổi nó cho:

<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/colorPrimaryDark</item> 
</style> 
+0

Tuyệt vời nó đã hoạt động, cảm ơn! – rauliyohmc

+1

Điều này là ok nếu bạn không muốn sử dụng ngăn điều hướng ví dụ để hiển thị với thanh trạng thái trong suốt ... – CaptRisky

+0

@CaptRisky, phải làm gì nếu tôi cũng muốn sử dụng ngăn điều hướng? – frozzyk

Các vấn đề liên quan