android app字型不隨系統字型大小起舞

重點有二

  1. 在activity set content之前寫死字型大小
  2. 字型大小: resource的fontscale數值
  val resources: Resources = myactivity.getResources()
  var fontScale:Float = 1.0f
  if (resources != null && resources.getConfiguration().fontScale !== fontScale) {
    val configuration: Configuration = resources.getConfiguration()
    configuration.fontScale = fontScale
    resources.updateConfiguration(configuration, resources.getDisplayMetrics())
  }
 // 在set content之前
 setContent {
 }

發表迴響