是否可以在使用Android资源的同时以编程方式更改应用程序的语言?
如果没有,是否可以请求特定语言的资源?
我想让用户从应用程序更改应用程序的语言.
当我点击"sub_changelang"按钮时,它应该将程序语言更改为法语.我得到以下代码来更改区域设置,但我不知道如何刷新/ pdate应用程序将语言更改为法语.
Button cl = (Button) findViewById(R.id.sub_changelang);
cl.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
Locale locale = new Locale("fr_FR");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
}
});
Run Code Online (Sandbox Code Playgroud)
它不起作用.我该如何解决?我试着添加:
MainActivity.this.getResources().updateConfiguration(config, MainActivity.this.getResources().getDisplayMetrics());
Run Code Online (Sandbox Code Playgroud)
但它不起作用.我也尝试过:
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
Run Code Online (Sandbox Code Playgroud)
它也没用.
android:configChanges="locale"
Run Code Online (Sandbox Code Playgroud)
在application-> activity下的AndroidMainfest.xml中设置