2

I'm using Theme.AppCompat.DayNight.NoActionBar for App theme and defined color resources for Day and Night theme using values-night qualifier

values/colors.xml

<color name="icon_color">#282C3C/color>

values-night/colors.xml

<color name="icon_color">#FFFFFF/color>

I've vector drawable which uses color resource from theme values

<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="9dp" android:height="6dp" android:viewportWidth="9" android:viewportHeight="6">
    <path
        android:pathData="M1.398 0.383l2.958 3.09c0.079 0.081 0.207 0.082 0.285 0l2.992-3.087C7.948 0.06 8.46 0.063 8.773 0.394c0.304 0.323 0.303 0.84-0.004 1.16L4.784 5.74c-0.157 0.165-0.415 0.165-0.573 0L0.233 1.577c-0.315-0.329-0.31-0.86 0.01-1.183l0.023-0.022C0.582 0.054 1.088 0.06 1.398 0.383z"
        android:fillColor="@color/icon_color" />
</vector>

I set this drawable using app:srcCompat="@drawable/wp_ic_camera" without any background or tint values and it uses AppCompatResources.getDrawable(view.context, drawableRes) in databinding to set the drawable

Users can choose the app theme to Light/Dark or System mode in App preference I update the theme using

 val nightMode = when (theme) {
            AppTheme.DARK -> AppCompatDelegate.MODE_NIGHT_YES
            AppTheme.LIGHT -> AppCompatDelegate.MODE_NIGHT_NO
            AppTheme.SYSTEM -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
        }
AppCompatDelegate.setDefaultNightMode(nightMode)

I have also updated ContextThemewrapper using latest theme chosen by user

The issue is when device theme is Dark and App theme is set to Light it follows System theme for drawable colors

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
AlgoCoder
  • 1,706
  • 5
  • 19
  • 40

0 Answers0