如何设置布局/ XML样式状态栏色调的颜色? [英] How to set status bar tint color in layout/style XML?

查看:632
本文介绍了如何设置布局/ XML样式状态栏色调的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了 windowTranslucentStatus 在我的应用程序的主题。

I'm using the windowTranslucentStatus in my app theme.

现在,也想着色状态栏,以配合我的动作条。

Now, also want to tint the status bar to match my ActionBar.

目前我使用的是 SystemBarTint 库,它主要是罚款,除非一个问题:

Currently I'm using the SystemBarTint library, which is mostly fine except of one problem:

在应用程序启动时,操作系统显示为主题的样机布局作为开机画面的实际通货膨胀中。在这个阶段,没有状态栏着色呢。

When the application launches, the OS shows a themed mockup layout as a splash image during the actual inflation. At that stage, there is no status bar tinting yet.

它看起来像(我花了5次捕获应用程序启动时这一​​截图):

It looks like that (Took me 5 times to capture this screenshot during app launch):

只有在活动满载色调被应用。这对我来说是一个问题,我在寻找一种方法以某种方式显示在发射过程中的状态栏的全部品牌。

Only after the activity is fully loaded the tint is applied. This is a problem for me and I'm looking for a way to somehow show the full branding on the status bar during launch.

我已经阅读本博客文章这就解释了,你怎么能真正控制哪些将在发射过程中通过指定要显示的 windowBackground

I have read This blog post Which explains how you can actually control what will be displayed during launch by specifying a windowBackground.

我设置了​​ windowBackground 来我的主要颜色 - >然后涂满整个屏幕呈粉红色。

I set the windowBackground to my main color -> then the entire screen painted pink.

我设置背景属性我活动的根元素为白色,但随后再次启动时,屏幕是粉红色的,并装有活动后才内容的背景变得明朗,白色。此行,但效果并不理想。

I set background property on my activity's root element to white, but then again during launch the screen is pink, and only after the activity is loaded the content's background clears to white. This OK but not ideal.

我知道我可以创建一个白色的背景和颜色,其中状态栏应该是一个位图,但它不会是主题能,这意味着我必须创建一个新的位图,如果主色变化

I know I can create a bitmap with a white background and a color where the status bar should be, but then it won't be theme-able, meaning I'll have to create a new bitmap if the main color changes.

所以,总结一下我的问题是:你知不知道一个方法来设置色调颜色XML中的状态栏(奇巧)

So to sum it up my question is this: Do you know a way to set a tint color for the status bar (in KitKat) in XML?

另外,是否有可能创建一个XML绘制将包含在顶部的彩条有一个固定的高度?

Alternatively, is it possible to create an XML drawable that will contain a colored bar at the top with a fixed height?

推荐答案

这是:

好知道别人挣扎完全相同的问题,像我一样。

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

要使它简单,我会在这里发布的XML绘制:

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>

现在,在我的主题我将这个绘制的 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>

这篇关于如何设置布局/ XML样式状态栏色调的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆