Taking advantage of the translucent status bar in Android 4.4 KitKat

后端 未结 5 990
抹茶落季
抹茶落季 2021-02-01 05:45

When I released my note taking application for Android 4.0 - 4.3 I used a custom action bar color with a custom action bar icon (instead of using the standard light and dark act

相关标签:
5条回答
  • 2021-02-01 05:50

    To change the color of the status bar to windowBackground

     <item name="android:windowBackground">@color/window_bg</item>
    

    To add the translucent effect to status and navigation bar

    <item name="android:windowTranslucentStatus">true</item>
    
    <item name="android:windowTranslucentNavigation">true</item>
    
    0 讨论(0)
  • 2021-02-01 05:52

    You're very close you just need to update your view background colors:

    <FrameLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#ffd060" >
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/background_light"
    
            <!-- your stuff here -->
        </LinearLayout>
    </FrameLayout>
    

    Specifying a global background color in your AppBaseTheme would also work but would likely cause a mess as it would end up been the default background color for everything.

    0 讨论(0)
  • 2021-02-01 05:55

    It looks like all you need to do is add this element to the themes you want a translucent status bar on:

    <item name="android:windowTranslucentStatus">true</item>
    
    0 讨论(0)
  • 2021-02-01 06:01

    Update: Found this great article from Matt Gaunt (a Google Employee) on adding a Translucent theme to Android apps. It is very thorough and addresses some of the issues many people seem to be having while implementing this style: Translucent Theme in Android

    Just add the following to your custom style. This prevents the shifting of the content behind the ActionBar and up to the top of the window, not sure about the bottom of the screen though.

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

    Credit: Transparent Status Bar System UI on Kit-Kat

    0 讨论(0)
  • 2021-02-01 06:05

    Add these lines in your main theme

    <style name="AppTheme" parent="android:Theme.Holo.Light">
        <item name="android:windowTranslucentStatus">true</item>
        <item name="android:windowTranslucentNavigation">true</item>
        <item name="android:fitsSystemWindows">true</item>
    </style>
    
    0 讨论(0)
提交回复
热议问题