2015-12-03 36 views
5

Tôi đang sử dụng AppCompat cho một cổng sau của thiết kế Material design trên các thiết bị trước Lollipop. Bằng cách nào đó, sự hỗ trợ toolbar phủ lên các status bar và tạo một bóng trên đó, như thể thanh trạng thái nằm phía sau thanh công cụ. Đã thử nghiệm trên điện thoại Android 5.0.2 của tôi.Lớp phủ Thanh công cụ và tạo bóng trên thanh trạng thái

enter image description here

Dưới đây là các mã:

bố trí Hoạt động

<android.support.design.widget.CoordinatorLayout 
    android:id="@+id/base_root" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/base_appbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/PGTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/base_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:popupTheme="@style/PGTheme.PopupOverlay"/> 

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

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

Theme-v21

<style name="PGTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
    <item name="colorPrimary">@color/base_color_2</item> 
    <item name="colorPrimaryDark">@color/base_color_1</item> 
    <item name="colorAccent">@color/base_color_2</item> 
    <item name="android:colorButtonNormal">@color/base_color_2</item> 
    <item name="android:textViewStyle">@style/PGTheme.TextView</item> 
    <item name="android:editTextStyle">@style/PGTheme.EditText</item> 
    <item name="android:buttonStyle">@style/PGTheme.Button</item> 
</style> 

<style name="PGTheme.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> 

Bất cứ ý tưởng tại sao điều này xảy ra?

Trả lời

10

Trong Phong cách của bạn loại bỏ các statusBarColor:

<item name="android:statusBarColor">@android:color/transparent</item> 

Vì vậy, chủ đề của bạn sẽ là:

<style name="PGTheme.NoActionBar"> 
    <item name="windowActionBar">false</item> 
    <item name="windowNoTitle">true</item> 
    <item name="android:windowDrawsSystemBarBackgrounds">true</item> 
</style> 

Hope this helps.

+1

Nó hoạt động. Và trong trường hợp bạn muốn thanh trạng thái trong suốt, bạn có thể theo dõi bài đăng này (và thay thế màu bằng Color.TRANSPARENT): http://stackoverflow.com/questions/26702000/change-status-bar-color-with -appcompat-actionbaractivity –

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