Android的材料:状态栏颜色不会改变 [英] Android Material: Status bar color won't change

查看:133
本文介绍了Android的材料:状态栏颜色不会改变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个简单的应用程序来测试材料设计。我使用 com.android.support:appcompat-v7:21.0.0 和我的活动是这样的:

I'm developing an simple app to test the material design. I'm using com.android.support:appcompat-v7:21.0.0 and my activity looks like:

public class MyActivity extends ActionBarActivity {
   ...
}

的布局定义为:

The layout is defined as:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MyActivity">

    <android.support.v7.widget.Toolbar
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="128dp"
        android:minHeight="?attr/actionBarSize"
        android:background="?attr/colorPrimaryDark"/>
</LinearLayout>

现在我定义我的主题下料原则:

Now i defined my theme following material guidelines:

<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary500</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark700</item>
</style>

我想改变状态栏的颜色在pre安卓5,并将其设置为 colorPrimaryDark 但我无法找到正确的路。我尝试使用:

I'd like to change the status bar color in pre Android 5 and set it to colorPrimaryDark but i can't find the way. I tried using:

getWindow().setStatusBarColor(..)

但setStatusBar颜色可从21级。 为什么如果我定义了一个 colorPrimaryDark 在我的主题,并使用appcompact状态栏不变色? 任何人都可以帮忙吗?

but setStatusBar color is available from level 21. Why if i define a colorPrimaryDark in my theme and use appcompact the status bar doesn't change color? Anyone can help?

推荐答案

状态栏是由操作系统所拥有的系统窗口。在pre-5.0 Android设备,应用程序无权改变其颜色,所以这是不是该AppCompat库可以为老年人平台版本的支持。最好的AppCompat所能做的就是在应用程序内着色动作条等常用UI小部件提供支持。

The status bar is a system window owned by the operating system. On pre-5.0 Android devices, applications do not have permission to alter its color, so this is not something that the AppCompat library can support for older platform versions. The best AppCompat can do is provide support for coloring the ActionBar and other common UI widgets within the application.

这篇关于Android的材料:状态栏颜色不会改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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