Taking advantage of the translucent status bar in Android 4.4 KitKat

浪子不回头ぞ 提交于 2019-12-02 18:11:02
thunsaker

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

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>

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>

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.

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>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!