2

在我支持 2 种语言英语和阿拉伯语的应用程序中,以下代码用于设置所选语言的区域设置。LTR 和 RTL 布局都适用于除小米、Redmi 设备之外的所有设备。在小米设备中,RTL 布局不起作用。

//main method

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        return updateResources(context, "ar"); // for English "en"
    }

//Code

private static Context updateResources(Context context, String language) {
    Locale locale = new Locale(language);
    Locale.setDefault(locale);

    Configuration configuration = context.getResources().getConfiguration();
    configuration.setLocale(locale);
    configuration.setLayoutDirection(locale);

    return context.createConfigurationContext(configuration);
}
4

0 回答 0