I am working on Night mode for my Android app. I'm using ContextCompat.getColor to get colours programmatically for some UI elements, however this method it's not fetching the correct colour. When the app is in Night mode, so adhering to the night resource qualifier, ContextCompat fetches the color from values/colors.xml and not values-night/colors.xml.
Curiosly, if I call ContextCompat.getColor from an Activity, it returns me the correct color
//get Actual Theme Colors
String bgColor = String.format("#%06X", (0xFFFFFF & ContextCompat.getColor(this, R.color.dialogBackground)));
String txtColor = String.format("#%06X", (0xFFFFFF & ContextCompat.getColor(this, R.color.dialogText)));
Instead, if I call ContextCompat.getColor from a Fragment inside an Activity, it returns the wrong color
//get Actual Theme Colors
bgColor = String.format("#%06X", (0xFFFFFF & ContextCompat.getColor(getActivity(),R.color.dialogBackground)));
txtColor = String.format("#%06X", (0xFFFFFF & ContextCompat.getColor(getActivity(),R.color.dialogText)));
I am using 'androidx.appcompat:appcompat:1.0.2' lib
I don't know if it's related to this bug
I hope you will find a solution or at least a workaround, such as getColor from a resource for a specific configuration (if possibile).