【发布时间】:2014-12-17 06:01:44
【问题描述】:
我正在开发一个简单的应用程序来测试材料设计。我正在使用com.android.support:appcompat-v7:21.0.0,我的活动看起来像:
public class MyActivity extends ActionBarActivity {
...
}
布局定义为:
<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>
现在我按照材料指南定义了我的主题:
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">@color/colorPrimary500</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark700</item>
</style>
我想在 Android 5 之前更改状态栏颜色并将其设置为colorPrimaryDark,但我找不到方法。我尝试使用:
getWindow().setStatusBarColor(..)
但是 setStatusBar 颜色从 21 级开始可用。
为什么如果我在主题中定义 colorPrimaryDark 并使用 appcompact 状态栏不会改变颜色?
有人可以帮忙吗?
【问题讨论】:
-
似乎是 appcompat-v7 中的一个错误。您介意在code.google.com/p/android/issues/list 提交问题以便我们跟踪吗?请在问题中包含您的布局和样式 XML。谢谢!
-
setStatusBarColor() 也应该有 WindowCompat 方法。随时在问题中提及或提交单独的问题。
-
感谢您的回答。我将对此问题进行更多调查,检查我是否做错了什么,如果我找不到打开问题的方式。
标签: android statusbar material-design