开发者

How to change localization in my android app without going to the settings? [duplicate]

This question already has answers here: 开发者_运维知识库 Changing Locale within the app itself (6 answers) Closed 8 years ago.

Ok i have an application with 2 different languages (english and german), how to change them from my application? When i click the Language button im using intent to com.android.settings.LocalePicker and from there i select the language. So instead of that i want to select English and German options from dialog box. I know how to create the dialog box, but don't know how to change the locale.


Application resources are fetched using the system local which isn't changeable from within an application.

The system settings screen uses a class (ActivityManagerNative) which isn't available via the SDK and thus can not be guaranteed to work between releases, and hence shouldn't be used in your code.

So your options are;

  • Don't offer the functionality in your app
  • Implement your own system for determining what setting the user has selected in your app and pulling the appropriate resources using your own code.


try this :

  1. create a normal android dialog with radio button selection of English & German
  2. OnCheckedChange ()

write this to change the Language

Locale myLocale = new Locale(/*String selected*/);
Locale.setDefault(myLocale );

Configuration config2 = new Configuration();
config2.locale = myLocale ;
getBaseContext().getResources().updateConfiguration(config2,
  getBaseContext().getResources().getDisplayMetrics());   
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜