当我启用深色模式时,我的应用程序上的某些菜单看起来很糟糕:非常暗的背景上的黑色文本。我对颜色完全是一个初学者。
我还没有接触过 android studio 上默认颜色设置的任何内容,所以我有默认的两个主题 XML 和 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>
And:
<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>
Color:
<?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 进行测试。感谢您的帮助
转到 Activity_main.xml 并将颜色保持黑色的 TextView 的 textColor 属性设置为
android:textColor = "?android:textColorPrimary"
Go to res/values/themes/themes.xml(夜间)并在下面添加以下代码<!-- Customize your theme here. -->
:
<item name="android:textColorPrimary">@color/white</item>
Go to 资源/值/主题/themes.xml并在下面添加以下代码<!-- Customize your theme here. -->
:
<item name="android:textColorPrimary">@color/black</item>
运行您的应用程序并更改为深色模式。它会起作用的。只需确保代码添加在</style>
关闭标签主题.xml and theme.xml(夜晚) files
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)