我正在开发一个简单的应用程序来测试材料设计。我正在使用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>我想更改前安卓5中的状态栏颜色,并将其设置为colorPrimaryDark,但我找不到方法。我试着用:
getWindow().setStatusBarColor(..)但是setStatusBar颜色可以从21层获得。为什么我在我的主题中定义了一个colorPrimaryDark并使用appcompact状态栏不改变颜色?有人能帮忙吗?
发布于 2014-11-15 16:36:59
使_Theme.AppCompa_t风格的父级
<style name="AppTheme" parent="Theme.AppCompat">
<item name="android:colorPrimary">#005555</item>
<item name="android:colorPrimaryDark">#003333</item>
</style>并将getSupportActionBar().getThemedContext()放在onCreate()中。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
getSupportActionBar().getThemedContext();
}https://stackoverflow.com/questions/26496411
复制相似问题