【问题标题】:Why has all my text turned black when set it in my android theme to be white?为什么在我的 android 主题中设置为白色时,我的所有文本都变黑了?
【发布时间】:2017-04-03 07:10:42
【问题描述】:

我试图在我的 AppTheme 中将我的 textview textColor 设为白色,但它在我的片段中显示为黑色。该片段已设置为具有如下背景:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:fillViewport="true"
    android:layout_height="wrap_content"
    android:id="@+id/fragment_settings"
    android:background="?android:attr/windowBackground"

页面现在看起来像这样:

主题如下:

<resources>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
     <!--   <item name="android:statusBarColor">@android:color/transparent</item> -->
    </style>

    <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/whiteText</item>
        <item name="android:buttonStyle">@style/MyButton</item>
        <item name="android:statusBarColor">@android:color/black</item>
        <item name="android:colorBackground">#2d314d</item>
        <item name="android:textColorPrimary">@color/whiteText</item>
        <item name="android:textColorPrimaryInverse">@android:color/holo_red_dark</item>
        <item name="android:textColorSecondary">@android:color/holo_blue_bright</item>
        <item name="android:textColorSecondaryInverse">@android:color/holo_red_dark</item>
        <item name="android:colorForeground">@android:color/holo_blue_bright</item>
        <item name="android:windowBackground">?android:attr/colorBackground</item>
    </style>

    <style name="MyButton" parent="android:Widget.Button">
        <item name="android:background">#FF5A79</item>

        <item name="android:textColor">@color/whiteText</item>

    </style>
</resources>

另外,不确定这是否相关,但以防万一,我使用的是主题编辑器,它给出了警告 - 与 colorButtonNormal 的对比度不足 - 由 android:textcolorPrimary。我不太了解 colorButtonNormal 是什么,也找不到任何有关它的信息。这是我的主题编辑器在我当前设置下的样子:

当我遇到另一个问题时,editText 字段(WEIGHT 和 AGE)内的文本颜色为白色,我需要将其更改为黑色。

感谢您的帮助,这个 android 样式的东西让我发疯了。

【问题讨论】:

  • 在清单中,您是否将主题设置为特定活动所需的主题?
  • 在清单中,活动的主题设置为 android:theme="@style/AppTheme.NoActionBar",我认为 android studio 是在创建活动时设置的。当我删除它或删除 NoActionBar 部分时,当我在模拟器上安装它时应用程序崩溃。
  • 尝试使用 android:theme="@style/AppTheme" 看看是否有效。
  • 试过了,它在启动时甚至可能在安装时崩溃。
  • 抛出的异常是什么,你的活动在扩展什么?

标签: android android-fragments android-theme


【解决方案1】:

去这个

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:fillViewport="true"
        android:layout_height="wrap_content"
        android:id="@+id/fragment_settings"
        android:background="@android:color/white"/>

这将解决您的问题。您正在设置 parent="Theme.AppCompat.Light.DarkActionBar" 这就是为什么一切都是黑色的

【讨论】:

  • 但是我覆盖了我的 AppTheme 中的文本颜色,为什么它们不适用?
  • 我刚刚尝试过,正如预期的那样,它只是将背景颜色变为白色,而不是文本视图中的文本颜色。上面的背景颜色是对的。
  • 你可以做一件事为 TextViews 定义白色的样式,然后你可以使用它来解决你的问题。
  • OK 会尝试,但为什么 AppTheme 中的颜色不能正常工作?
  • 这是android sdk的默认样式,我们不能编辑那个样式。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-07-18
  • 2016-05-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-06
  • 1970-01-01
相关资源
最近更新 更多