Android-更改Android应用程序中的语言不工作

Android-更改Android应用程序中的语言不工作,android,localization,Android,Localization,我正在尝试对我的android应用程序进行本地化。除非我强制停止应用程序并在语言更改后启动它,否则不会更改错误消息 public interface ApplicationConstants { Resources res = MyActivity.getInstance().getAppContext().getResources(); public static final String NETWORK_ERROR_MESS=res.getString(R.string.str_netwo

我正在尝试对我的android应用程序进行本地化。除非我强制停止应用程序并在语言更改后启动它,否则不会更改错误消息

public interface ApplicationConstants {

Resources res = MyActivity.getInstance().getAppContext().getResources();
public static final String NETWORK_ERROR_MESS=res.getString(R.string.str_network_error);
public static final String AUTH_ERR=res.getString(R.string.str_auth_error);

 }
res->values
文件夹中

Strings.xml

 <string name="str_network_error"> Network Error english.</string>
<string name="str_auth_error">Authentication failure english.</string>
 <string name="str_network_error"> Network Error france.</string>
<string name="str_auth_error">Authentication failure france.</string>

尝试以下方法:当您的主要活动加载时

Locale locale = new Locale("fr");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
并在活动中获取
字符串
,如

String NETWORK_ERROR_MESS=youractivity.this.getString(R.string.str_network_error);
String AUTH_ERR=youractivity.this.getString(R.string.str_auth_error);

恕我直言,您所有的问题都是由于接口使用不当造成的。

有关详细信息,请阅读

我已尝试设置本地语言,并且我的代码正在到达代码的特定部分,因此现在已设置语言。但消息仍然没有更改。我正在按照您提供的链接解决方案中指定的过程进行操作。