我在Android 7的设备上实现了androidx的生物识别库后,我的应用中出现了问题。当在手机的无障碍设置中改变字体大小时,我的主应用就开始出现问题,而应用中的文字大小并没有改变。在确定问题后,我创建了一个带有单个 "hello world "活动的虚拟应用,我发现即使只在app.gradle中声明库的依赖关系也会重现这个bug。这是活动的xml。
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
这是build. gradle:
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.fontscaletestapplication"
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation "androidx.biometric:biometric:1.0.1"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
值得一提的是,如果我删除了androidx生物识别的依赖关系,字体缩放就没有任何问题,但只要我添加了这个依赖关系,改变字体大小就不会对应用中的字体大小产生影响。
从我在主应用中注意到的情况来看,我认为这与应用上下文和应用资源有关,但我想不出问题出在哪里。我在HTC 10上用Android 7和模拟器上用API 24进行了测试。另外值得一提的是,字体缩放在Android 9和10上也能正常工作。
我是不是有什么地方遗漏了?
谢谢你。
是由以下原因造成的 https:/issuetracker.google.comissues140607881。
根据该bug:"API 26之前的所有版本都会受到影响,Android 8.0是第一个可以用App compat 1.1.0全局改变字体大小的版本。"
"在最新的AppCompat 1.2.0-alpha02中修正"
我测试了最新的1.2.0-beta01,修复成功。以下是appcomat的所有版本 https:/developer.android.comjetpackandroidxreleasesappcompat。.