我有一个与此问题非常相似的问题:Language change issue after updating to androidx.appcompat:appcompat:1.1.0,但它对于Api 24及以下版本非常有效,但对于Api 26及以上版本完全无效(无法测试) Api 25)。
等级依赖性
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.0.2' //DO NOT UPGRADE - Translation issue
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
testImplementation 'androidx.test.espresso:espresso-core:3.2.0'
testImplementation 'androidx.test:core:1.2.0'
testImplementation 'androidx.test.ext:junit:1.1.1'
implementation 'com.google.android.material:material:1.0.0'
implementation fileTree(include: ['*.jar'], dir: 'libs')
}
点击按钮时触发的代码
/**
* Select language application
*/
public static void defineLanguage(ImageButton button, final String value, final Activity activity, final Activity source) {
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Locale locale = new Locale(value);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
activity.getApplicationContext().getResources().updateConfiguration(config,
activity.getBaseContext().getResources().getDisplayMetrics());
Intent intent = new Intent(activity, source.getClass());
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
activity.finish();
activity.startActivity(intent);
}
});
}
我还应该等待Google修复问题,还是我的问题略有不同?