gpt4 book ai didi

android - Android Oreo 中的 RTL 布局错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:27:06 26 4
gpt4 key购买 nike

自从我在移动设备上升级到 android oreo 后,我对应用程序的 RTL 支持就无法正常工作。它将字符串更改为阿拉伯语但不更改布局方向。但是如果我对任何低于 oreo 的设备运行相同的 RTL 转换,一切正常。还有其他人遇到过这个问题吗?关于此错误和解决方法是否有任何官方声明?

下面是我更改语言环境的方法

public static boolean setDefaultLocale(Context context) {
Resources resources = context.getResources();
PreferenceManager preferenceManager = PreferenceManager.getInstance();
String localLanguage = resources.getConfiguration().locale.getLanguage();
boolean isLanguageChanged = !preferenceManager.getCurrentLanguageCode().equalsIgnoreCase(localLanguage);
if (isLanguageChanged) {
Log.d("", preferenceManager.getCurrentLanguageCode());
Locale locale = new Locale(preferenceManager.getCurrentLanguageCode());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
Locale.setDefault(Locale.Category.DISPLAY, locale);
else
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
resources.updateConfiguration(config, resources.getDisplayMetrics());
((Activity) context).recreate();
}
return isLanguageChanged;
}

最佳答案

在 onCreate 函数中添加以下代码进行简单修复:

if (Locale.getDefault().getLanguage()=="ar")
getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
else
getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_LTR);

关于android - Android Oreo 中的 RTL 布局错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46296202/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com