如果用户需要,我有2个英语和阿拉伯语按钮用于更改语言。按下这两个按钮,语言在我实现代码的所有活动中都在变化,但是没有存储这种语言,请您提供此代码的解决方案
public class Common
{
private static final String LAN_STORE_KEY = "lan_store_key" ;
public static void setAppLanguage(Context context, String lang) {
//APP_LANG = lang;
Editor editor =
context.getSharedPreferences(LAN_STORE_KEY, Activity.MODE_PRIVATE).edit();
editor.putString("key", lang);
editor.commit();
System.out.println("getAppLanguage(getApplicationContext()===inside set==>"+getAppLanguage(context));
}
public static String getAppLanguage(Context context) {
//return APP_LANG;
SharedPreferences savedSession =
context.getSharedPreferences(LAN_STORE_KEY, Activity.MODE_PRIVATE);
//System.out.println("getAppLanguage(getApplicationContext()===inside get==>"+getAppLanguage(context));
return savedSession.getString(LAN_STORE_KEY, "") ;
}