How to set status bar tint color in layout/style XML?

喜欢而已 提交于 2019-12-03 22:58:49
Avi Shukron

Here it is: The (almost) perfect answer

Good to know that someone else was struggling the exact same problem like me.

To make it simple I'll post here the XML drawable:

window_background.xml:

<?xml version="1.0" encoding="utf-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:id="@+id/status_bar_background"
          android:drawable="@color/main_app_color"/>

    <item android:id="@+id/content_window_background"
        android:drawable="@color/white"
        android:top="25dp"/>
</layer-list>

And now in my theme I assign this drawable as the windowBackground:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="AppTheme" parent="BaseAppTheme">
        <!-- Customize your theme here. -->
        <item name="android:windowTranslucentNavigation">@bool/translucent_nav_bar</item>
        <item name="android:windowTranslucentStatus">true</item>
        <item name="android:windowBackground">@drawable/window_background</item>
    </style>
</resources>
Takhion

As I have replied here, you can see a full working example I created here (unfortunately too long to copy, but rest assured that repo is going nowhere!).

Oh and from Lollipop onwards there won't be any need for tricks ;)

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