我正在开发一个简单的应用程序来测试 Material Design。我正在使用 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>
现在我按照Material设计准则定义了我的主题:
<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(..)
但是在 API 级别 21 及以上,可以使用 setStatusBar 颜色。为什么如果我在主题中定义了 colorPrimaryDark
并使用 appcompact,则状态栏不会更改颜色?有人能帮忙吗?