Changing light/dark mode not works for color resources
See original GitHub issueAppIntro Version: current master (SNAPSHOT)
Device/Android Version: Emulator / Android 11 (API level 30)
Issue details / Repro steps / Use case background: If the intro is open and the dark mode configuration changes not all colors are changed.
- Open intro in light mode
- Change theme to dark mode by control center
The drawables (set by resource ID) will be changed like expected. All background & font colors (that set directly) does not change.
After the design mode changed the activity will recreated. The slides will added again with new (dark mode) parameters. The colors are set directly and I found that the onActivityCreated AppIntroBaseFragment.kt#L73 method is called while recreating with the “old” parameters and the explicit set colors will be reused.
The simplest solution is to give a color resource ID instead of the color itself. As more cleaner solution we should improve the instance saving flow to keep them per fragment itself instead to referencing to the activity lifecycle.
Your Code:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Have default + night variants
// Works fine
setIndicatorColor(
selectedIndicatorColor = ContextCompat.getColor(this, R.color.intro_pagination_indicator),
unselectedIndicatorColor = ContextCompat.getColor(this, R.color.meta_grey)
)
// Have default + night variants
// Works fine
setBackArrowColor(ContextCompat.getColor(this, R.color.accent))
setNextArrowColor(ContextCompat.getColor(this, R.color.accent))
setColorDoneText(ContextCompat.getColor(this, R.color.paper))
addSlide(AppIntroFragment.newInstance(
// ...
// Has default + night variant
// Works fine
imageDrawable = R.drawable.ic_logo,
// Has default + night variant
// Does NOT work
titleColor = ContextCompat.getColor(this, R.color.text),
// Has default + night variant
// Does NOT work
descriptionColor = ContextCompat.getColor(this, R.color.text),
// Has default + night variant
// Does NOT work
backgroundColor = ContextCompat.getColor(this, R.color.paper),
// ...
))
}
Working light:
Failed dark:
Expected result:
I will playing around a little bit and make a PR next days.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top GitHub Comments
Thanks for the reproducer 👍 That’s definitely a bug/improvement for the future.
+1 for this. We should add 3 new parameters to the
SliderPage
:And potentially start a deprecation cycle for the former
@ColorInt
parametersThat’s also a plus but unrelated to this bug.
Not really, but @Fabi755 might have a fix incoming? 😁