this solutions is with Kotlin and without using the deprecated function resources.updateConfiguration
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
adjustFontScale(resources.configuration)
}
private fun adjustFontScale(configuration: Configuration?) {
configuration?.let {
it.fontScale = 1.0F
val metrics: DisplayMetrics = resources.displayMetrics
val wm: WindowManager = getSystemService(Context.WINDOW_SERVICE) as WindowManager
wm.defaultDisplay.getMetrics(metrics)
metrics.scaledDensity = configuration.fontScale * metrics.density
baseContext.applicationContext.createConfigurationContext(it)
baseContext.resources.displayMetrics.setTo(metrics)
}
}
Observation: this is the same solution as the above but udpated with Kotlin