colorPrimaryDark未申请状态栏

时间:2016-01-24 08:25:16

标签: android android-toolbar

有关信息,我使用的是Android Studio 2.0 Preview 7,API 23。

有问题的活动 Activity that doesn't apply the theme

<?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
android:name=".OfferRide"
android:label="@string/title_activity_offer_ride"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan|stateAlwaysVisible"
android:theme="@style/AppTheme.NoActionBar" />

事情正常的其他活动。 enter image description here

文件: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>

4 个答案:

答案 0 :(得分:1)

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

  

AppBarLayoutvertical LinearLayout,它实现了许多   材料设计app bar概念的特征,即滚动   手势。

     

儿童应该通过提供他们想要的滚动行为   setScrollFlags(int)和关联的布局xml属性:   应用:layout_scrollFlags

     

此视图在很大程度上取决于将用作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);

答案 1 :(得分:0)

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

这是我在 AndroidManifest.xml

中的活动

enter image description here

这是我的第一个 styles.xml (默认) enter image description here

这是我的第二个 styles.xml (V21) enter image description here

处于运行模式的应用使用第二种样式,但有问题,因为看不到应用的 colorPrimaryDark

解决方案是,在第二个style.xml中的最后一个项目中注释如下。 enter image description here

我希望这会有所帮助!

问候!

答案 2 :(得分:0)

对我来说,问题是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>

答案 3 :(得分:-1)

只需在styles.xml

中尝试使用它
<item name="android:statusBarColor">@color/colorPrimaryDarkBlue</item>

希望它能正常工作