android - colorPrimaryDark 未申请状态栏中的特定 Activity

标签 android android-toolbar

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

有问题的 Activity 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>

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

为了修复它,我在上面的相对布局中添加了 ScrollView 。

Activity 的 list 部分如下

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

其他一切正常的 Activity 。 enter image description here

文件:样式.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>

最佳答案

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

这是我在 AndroidManifest.xml 中的 Activity :

enter image description here

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

enter image description here

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

enter image description here

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

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

enter image description here

关于android - colorPrimaryDark 未申请状态栏中的特定 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34973629/

相关文章:

android - 单击时不要将按钮置于前台

android - Android中布局参数动画的低性能

iphone - localytics 没有给报告?

android - 工具栏后退按钮功能

android - 使用 Material 指标创建 android 工具栏

android - 如何在 android 中使用 Canvas 绘制圆环?

安卓。 2D游戏开发

android - 禁用长按 SearchView EditText

android-layout - 影响工具栏样式和定位的抽屉导航片段