colorPrimaryDark 未在状态栏中申请特定 activity

colorPrimaryDark is not applying for particular activity in Status Bar

有关信息,我正在使用 Android Studio 2.0 Preview 7,API 23.

Activity 有问题

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="in.ezyride.blovia.OfferRide"
    android:fitsSystemWindows="true">
    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay"
        android:id="@+id/view">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>
    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/view">
        <include
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:id="@+id/basicLayoutAddl"
            layout="@layout/content_offer_ride"
            />
    </ScrollView>
</RelativeLayout>

但其他活动是有规律的。这发生在我试图修复覆盖 EditText 的键盘问题时。但是我几乎解决了这个问题,提出了新问题。

为了修复它,我在上面的相对布局中添加了滚动视图。

activity清单部分如下

<activity
android:name=".OfferRide"
android:label="@string/title_activity_offer_ride"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan|stateAlwaysVisible"
android:theme="@style/AppTheme.NoActionBar" />

其他activity处一切正常。

文件:styles.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>

        <item name="md_positive_color">@color/colorPrimary</item>
        <item name="md_neutral_color">@color/colorPrimary</item>
        <item name="md_title_color">@color/colorPrimary</item>
        <item name="md_negative_color">@color/colorPrimary</item>
        <item name="md_widget_color">@color/colorPrimary</item>
    </style>

    <style name="FullscreenTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowActionBarOverlay">true</item>
        <item name="android:windowBackground">@null</item>
        <item name="metaButtonBarStyle">?android:attr/buttonBarStyle</item>
        <item name="metaButtonBarButtonStyle">?android:attr/buttonBarButtonStyle</item>
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>

http://developer.android.com/reference/android/support/design/widget/AppBarLayout.html

AppBarLayout is a vertical LinearLayout which implements many of the features of material designs app bar concept, namely scrolling gestures.

Children should provide their desired scrolling behavior through setScrollFlags(int) and the associated layout xml attribute: app:layout_scrollFlags.

This view depends heavily on being used as a direct child within a CoordinatorLayout

使用 CoordinatorLayout 代替 RelativeLayout 代替 ScrollView,使用 NestedScrollView.

并更改此:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

至:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

因为您已经有了 Toolbar,让我们假设您已经在 OnCreate 中添加了这个:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

在你的styles.xml中使用这个:

<item name="android:statusBarColor">@color/colorPrimaryDarkBlue</item>

在我的例子中,问题是因为我的项目中有两个文件 styles.xml,这两个文件的活动主题名称相同。 让我描述一下。

这是我的 activity 在 AndroidManifest.xml:

这是我的第一个styles.xml(默认):

这是我的第二个styles.xml (V21):

运行模式下的应用使用了第二种样式,它有问题,因为我们看不到应用的colorPrimaryDark

解决方案是,在第二个中注释最后一项style.xml:

对我来说,问题是 windowTranslucentStatus:

之前:

<style name="MyTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="android:colorPrimary">@color/bright_purple</item>
        <item name="android:colorPrimaryDark">@android:color/background_dark</item>
        <item name="android:windowTranslucentStatus">true</item>
</style>

之后:

<style name="MyTheme" parent="Theme.AppCompat.NoActionBar">
            <item name="android:colorPrimary">@color/bright_purple</item>
            <item name="android:colorPrimaryDark">@android:color/background_dark</item>
    </style>