7

当我启用暗模式时,我的应用程序上的某些菜单看起来很糟糕:非常暗背景上的黑色文本。我完全是色彩方面的初学者。

在此处输入图像描述

我还没有在 android studio 的默认颜色设置上碰过任何东西,所以我有默认的两个主题 XMLs 和 Color Xml:

     <resources xmlns:tools="http://schemas.android.com/tools">
     <!-- Base application theme. -->
     <style name="Theme.TestSS" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
         <!-- Primary brand color. -->
         <item name="colorPrimary">@color/purple_500</item>
         <item name="colorPrimaryVariant">@color/purple_700</item>
         <item name="colorOnPrimary">@color/white</item>
         <!-- Secondary brand color. -->
         <item name="colorSecondary">@color/teal_200</item>
         <item name="colorSecondaryVariant">@color/teal_700</item>
         <item name="colorOnSecondary">@color/black</item>
         <!-- Status bar color. -->
         <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
         <!-- Customize your theme here. -->
     </style>

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

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

     <style name="Theme.TestSS.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
   </resources>

和:

    <resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Base application theme. -->
     <style name="Theme.TestSS" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
         <!-- Primary brand color. -->
         <item name="colorPrimary">@color/purple_200</item>
         <item name="colorPrimaryVariant">@color/purple_700</item>
         <item name="colorOnPrimary">@color/black</item>
         <!-- Secondary brand color. -->
         <item name="colorSecondary">@color/teal_200</item>
         <item name="colorSecondaryVariant">@color/teal_200</item>
         <item name="colorOnSecondary">@color/black</item>
         <!-- Status bar color. -->
         <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
         <!-- Customize your theme here. -->
     </style>
    </resources>

颜色:

   <?xml version="1.0" encoding="utf-8"?>
     <resources>
      <color name="purple_200">#FFBB86FC</color>
      <color name="purple_500">#FF6200EE</color>
      <color name="purple_700">#FF3700B3</color>
      <color name="teal_200">#FF03DAC5</color>
      <color name="teal_700">#FF018786</color>
      <color name="black">#FF000000</color>
      <color name="white">#FFFFFFFF</color>
     </resources>

问题在哪里?我正在 Android R 上使用 AVD 进行测试,并在我的物理设备上使用 Android Q 进行测试。感谢您的帮助

4

7 回答 7

9

转到您的 activity_main.xml 并将颜色保持为黑色的 TextView 的 textColor 属性设置为

android:textColor = "?android:textColorPrimary"

转到res/values/themes/themes.xml (night)并在下面添加以下代码<!-- Customize your theme here. -->

<item name="android:textColorPrimary">@color/white</item>

转到res/values/themes/themes.xml并在下面添加以下代码<!-- Customize your theme here. -->

<item name="android:textColorPrimary">@color/black</item>

运行您的应用程序并更改为暗模式。它会工作的。只需确保在themes.xmlthemes.xml(夜间)文件中的</style>结束标记之前添加代码

于 2021-02-24T18:16:14.640 回答
3

将此行中的颜色更改为其他颜色,这应该可以

     <item name="android:textColor">@android:color/holo_red_light</item>
于 2020-11-23T16:37:45.050 回答
3

要更改菜单背景,请将以下行添加到您的样式中:

<item name="android:itemBackground">@color/your_color</item>
于 2020-11-23T17:59:48.287 回答
1

只需要添加这个@color/white,确保你已经在清单中声明了你的主题名称。

<style name="Theme.UserRestaurant" parent="Theme.MaterialComponents.Light.DarkActionBar">
    <!-- Primary brand color. -->
    <item name="colorPrimary">@color/orange</item>
    <item name="colorPrimaryVariant">@color/orange_dark</item>
    <item name="colorOnPrimary">@color/white</item>
    <item name="android:background">@color/white</item>


    <!-- Secondary brand color. -->
    <item name="colorSecondary">@color/teal_200</item>
    <item name="colorSecondaryVariant">@color/teal_700</item>
    <item name="colorOnSecondary">@color/black</item>
    <!-- Status bar color. -->
    <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
    <!-- Customize your theme here. -->
</style>
于 2021-02-01T07:39:46.010 回答
1

你如何设置文本颜色 没有为文本设置颜色?

尝试更改此值 @color/black 因为它是唯一与文本颜色匹配的颜色

于 2020-11-23T16:16:08.880 回答
0

激活夜间模式时更改文本视图的文本颜色

 public void checkNightModeActivated() {
        if (preferences.getBoolean ( KEY_ISNIGHTMODE,false )) {
            nightmode.setChecked ( true );
            AppCompatDelegate.setDefaultNightMode ( AppCompatDelegate.MODE_NIGHT_YES );

TextView textView=findViewById (R.id.textView );
TextView.setcolor(color.white);
于 2022-02-17T09:20:58.410 回答
0

要将夜间的颜色更改为白色,并将灯光更改为黑色,然后使用下面的代码。

• 打开res/drawable/values/themes.xml并将此代码放入其中。

     <item name="android:textColorPrimary">@color/black</item>

• 然后打开res/drawable/values/themes.xml(night)并将此代码放入其中。

   <item name="android:textColorPrimary">@color/white</item>

• 最后一步应用在Activity 或片段的TextView 中,将这一行放入其中。

  android:textColor = "?android:textColorPrimary"

完成保留代码☻♥

于 2022-01-21T13:43:22.657 回答