我正在开发一个简单的应用程序来测试材质设计。我使用com.android.support:appcompat-v7:21.0.0
和我的活动是这样的:Android材质:状态栏颜色不会改变
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">@color/colorPrimary500</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark700</item>
</style>
我想:
<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>
现在我下面的材料管理准则定义我的主题:
public class MyActivity extends ActionBarActivity {
...
}
为布局定义喜欢在Android 5之前更改状态栏颜色,并将其设置为colorPrimaryDark
,但我找不到方法。我试着使用:
getWindow().setStatusBarColor(..)
但setStatusBar颜色可从21级 为什么,如果我定义我的主题colorPrimaryDark
和使用appcompact状态栏不变色? 任何人都可以提供帮助吗?
似乎就像appcompat-v7中的一个bug。您是否介意在https://code.google.com/p/android/issues/list/上提交问题,以便我们跟踪该问题?请在问题中包含您的布局和样式XML。谢谢! – alanv 2014-10-21 23:00:01
还应该有setStatusBarColor()的WindowCompat方法。随意在问题中提及或单独提出问题。 – alanv 2014-10-21 23:01:05
Thx alanv为您的答案。我会在这个问题上进行更多的调查,检查我是否犯了错误,如果我找不到解决问题的方法。的 – FrancescoAzzola 2014-10-22 07:12:16