我想根据当前应用程序的语言/语言环境更改textview的文本

问题描述 投票:0回答:1

当前,我正在通知中显示从DB获取的所有通知。与登录之前一样,我将应用程序语言选择为阿拉伯语或英语,因此在通知屏幕中,我需要根据应用程序语言使用阿拉伯语或英语进行所有通知。但是,当我在模拟器上运行时,屏幕方向已更改为RTL,但某些文本未转换为阿拉伯语,因为我已在string.xml文件中同时添加了英语和阿拉伯语字符串。

示例:

String title = String.format(locale,notificationsFragment.getResources().getString(R.string.payment_received));
            Log.d("NotificationsAdapter", "notification == "+title);
            textTitle.setText(title);
android arabic
1个回答
0
投票

您需要将配置设置为尝试从中获取数据的语言环境。尝试使用以下功能。

public String getStringForLocale(Context context, Locale locale, int stringId) {  
    Configuration config = new Configuration(context.getResources().getConfiguration()); 
    config.setLocale(locale);   
    return context.createConfigurationContext(config).getText(stringId);
}
© www.soinside.com 2019 - 2024. All rights reserved.