TL,DR;
ContextCompat.getColor()
should use night colors (values-night/colors.xml
) when night mode is enabled but it currently does not. The issue arises when implementing a dark theme for an Android app using AppCompatDelegate.setDefaultNightMode()
. Colors change correctly between normal and dark modes based on the values set in values/colors.xml
and values-night/colors.xml
, but ContextCompat.getColor()
continues to use the normal colors instead of the appropriate night colors. This issue may be resolved by adjusting the settings in your build.gradle
file.
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0-beta01'
请问我做错了什么?
PS:我已经看过以下问题,但它没有回答我的问题https://dev59.com/trbna4cB1Zd3GeqPVho4
ContextCompat.getColor()
的两种颜色都返回有效值。您能否用代码片段详细说明您的问题(当您更改夜间模式/获取颜色时)? - Pawel