Android Oreo中的RTL布局错误 [英] RTL layout bug in android Oreo

查看:58
本文介绍了Android Oreo中的RTL布局错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Ever since I upgraded to android oreo on mobile my RTL support for application is not working. it's changing the strings to Arabic but not changing layout direction. but if I run same RTL shift to any of device lower than oreo, everything works fine. anyone else experienced this issue? is there any official statement yet about this bug and workaround?

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

Below is my method to change the locale

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函数中的简单修复中添加以下代码:

Simple fix in your onCreate function add the following code:

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

这篇关于Android Oreo中的RTL布局错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆