2015-11-29 44 views
11

Tôi gặp sự cố với thanh trạng thái của mình bị chồng chéo lên thanh công cụ.Thanh trạng thái chồng lên thanh công cụ

Tôi muốn có chức năng khi người dùng cuộn xuống ListView, thanh công cụ sẽ biến mất sau thanh trạng thái sao cho chỉ các tab hiển thị, giống như trong ứng dụng WhatsApp và YouTube.

Để đạt được hiệu ứng này hoặc để có được chức năng này, tôi sử dụng dòng này:

app:layout_scrollFlags="scroll|enterAlways" 

vào android.support.v7.widget.Toolbar của tôi, nhưng biết như tôi đã nói trước đó, trên thanh trạng thái bị chồng chéo bởi thanh công cụ.

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> 

Thankful cho bất kỳ sự giúp đỡ!

UPDATE:

v21 \ styles.xml

<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">@android:color/transparent</item> 
    </style> 
</resources> 

styles.xml

<resources> 

    <!-- Base application theme. --> 
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
     <!-- Customize your theme here. --> 
     <item name="colorPrimary">@color/colorPrimary</item> 
     <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
     <item name="colorAccent">@color/colorAccent</item> 
    </style> 
    <style name="AppTheme.NoActionBar"> 
     <item name="windowActionBar">false</item> 
     <item name="windowNoTitle">true</item> 
    </style> 
    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> 
    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /> 

</resources> 

enter image description here

+0

Xin vui lòng gửi theo phong cách hoạt động này được sử dụng từ styles.xml bạn – asadmshah

+0

@asadmshah tôi cập nhật bài của tôi – Ron

Trả lời

15

Hãy thử thêm android:fitsSystemWindows="true"-android.support.design.widget.AppBarLayout hoặc @style/AppTheme.PopupOverlay phong cách

0.123.
+1

bây giờ tôi đã có hiệu lực thi hành mà tôi muốn, nhưng thông báo của tôi thanh quay trắng @mdtuyen – Ron

+1

bạn có thể sử dụng 'setStatusBarColor (int color)' trong mã hoặc thay đổi kiểu để sửa chữa nó – phongvan

+2

Tôi đã tìm thấy một cách khác @ color/colorPrimaryDark là okey đó hoặc Tôi sẽ có bất kỳ vấn đề với điều đó? @mdtuyen – Ron

0

hãy thử làm android:layout_height="?attr/actionBarSize" cho android.support.v7.widget.Toolbar

2

này làm việc cho tôi để có được một lớp phủ màu trắng trên thanh trạng thái thiết bị (vấn đề sau khi cập nhật trong câu hỏi)

tôi đã thay đổi:

<item name="android:windowDrawsSystemBarBackgrounds">true</item> 

để

<item name="android:windowDrawsSystemBarBackgrounds">false</item> 

trong tệp styles.xml

của tôi
+2

Trong trường hợp của tôi, nó đã thay đổi màu sắc bình thường của thanh trạng thái thành màu đen. – CoolMind

+0

@CoolMind thấy [link] này (http://matthewwear.xyz/no-excuses-it-takes-5-mins-make-that-drawer-visible-under-your-status-bar-2/) nó mô tả cách hoạt động chi tiết –

+0

Documents chính thức về cùng một chủ đề: https://developer.android.com/reference/android/R.attr.html#windowDrawsSystemBarBackgrounds –

3

trong v21\styles.xml

loại bỏ <item name="android:statusBarColor">@android:color/transparent</item>

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