【问题标题】:Color Primary Dark is not working颜色原色暗不工作
【发布时间】:2016-07-11 22:12:19
【问题描述】:

我之前在 color.xml 文件中设置了原色暗色,状态栏颜色与原色原色相同!但几个小时前,我制作了一个菜单资源文件,并在我的工具栏中创建了一个搜索按钮!当我运行我的代码时,我看到原色暗色消失了并且不起作用。我搜索了很多以了解问题所在,但我没有找到任何东西。请指导我解决此问题。

样式.xml:

<!-- Base application theme. -->
<style name="AppTheme" parent="AppTheme.Base">

</style>

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

</style>

风格-v21:

<style name="AppTheme" parent="AppTheme.Base">
    <!-- Customize your theme here. -->
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:navigationBarColor">@color/colorNavBar</item>
    <item name="android:windowContentTransitions">true</item>
    <item name="android:windowAllowEnterTransitionOverlap">true</item>
    <item name="android:windowAllowReturnTransitionOverlap">true</item>
    <item name="android:windowSharedElementEnterTransition">@android:transition/move</item>
    <item name="android:windowSharedElementExitTransition">@android:transition/move</item>
</style>

工具栏.xml:

<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:minHeight="?attr/actionBarSize"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:background="?attr/colorPrimary"
android:layout_gravity="start">
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/toolbar_title"
    android:text="@string/app_name_persian"
    android:textSize="19sp"
    android:textStyle="bold"
    android:textColor="@android:color/white"
    android:layout_gravity="right"/>
<EditText
    android:layout_marginRight="20dp"
    android:id="@+id/searchEditText"
    android:layout_width="180dp"
    android:textSize="10sp"
    android:hint="@string/search_hint"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:visibility="invisible"/>

颜色.xml:

<resources>
<color name="colorPrimary">#0cac77</color>
<color name="colorPrimaryDark">#73ac95</color>
<color name="colorAccent">#20efd6</color>
<color name="colorNavBar">#73ac95</color>
<color name="colorNavDrawerBackColor">#f4f3f3</color>
<color name="colorCreationDate">#4acc82</color>
<color name="colorDeadDate">#d77177</color>
<color name="colorDutyName">#e5e8e9</color>

【问题讨论】:

    标签: android xml


    【解决方案1】:

    在我的代码中,正如@TheAnonymous010 所提到的,我刚刚将主布局设置为 CoordinatorLayout(我已将其设置为我的 RelativeLayout 的父级)。

    <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        tools:context="com.example.MyActivity">
    
        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:id="@+id/main_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/colorPrimaryDark"
            android:orientation="vertical"
            android:padding="15dp">
    
            ....
            ....
    
        </RelativeLayout>
    </android.support.design.widget.CoordinatorLayout>
    

    【讨论】:

      【解决方案2】:

      如果您尝试更改工具栏的颜色,您可能需要将android:backgroundandroid:background="?attr/colorPrimary" 更改为android:background="?attr/colorPrimaryDark"

      【讨论】:

      • 不,我不想改变工具栏的背景!我想像以前一样用颜色原色更改状态栏的颜色!
      • 确保你有一个 CoordinatorLayout 作为主布局。有时状态栏颜色不会显示,除非您的主布局是 CoordinatorLayout。
      【解决方案3】:

      不要覆盖您的主题。从您的工具栏中删除此属性:

      app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
      

      【讨论】:

      • 对不起,我在几秒钟前尝试过你的方法,但我不是解决方案 :(
      【解决方案4】:

      只需将android:backgroundandroid:background="?attr/colorPrimary" 替换为android:background="@color/colorPrimaryDark"

      【讨论】:

        【解决方案5】:

        我找到了答案!

        我在主活动的 xml 的根布局的属性中使用了android:fitsSystemWindows="true",以避免在用户使用键盘输入时移动窗口,但我通过将这个android:windowSoftInputMode="adjustPan" 放在清单文件的活动属性中来修复它!

        【讨论】:

          猜你喜欢
          • 2020-02-21
          • 1970-01-01
          • 2019-05-09
          • 2016-02-12
          • 1970-01-01
          • 2021-11-10
          • 1970-01-01
          • 1970-01-01
          • 2013-01-12
          相关资源
          最近更新 更多