Android编程实现动态支持多语言的方法
本文实例讲述了Android编程实现动态支持多语言的方法。分享给大家供大家参考,具体如下:
资源文件values/strings.xml中添加
English test
创建values-en文件夹,添加资源文件strings.xml:
English test
创建values-zh文件夹,添加资源文件strings.xml
Chinese 测试
MainActivitylayout中添加测试控件
MainActivity中添加代码:
publicclassMainActivity...
{
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
...
updateResources(this,"zh");
...
}
}
privatestaticbooleanupdateResources(Contextcontext,Stringlanguage){
Localelocale=newLocale(language);
Locale.setDefault(locale);
Resourcesresources=context.getResources();
Configurationconfiguration=resources.getConfiguration();
configuration.locale=locale;
resources.updateConfiguration(configuration,resources.getDisplayMetrics());
returntrue;
}
更多关于Android相关内容感兴趣的读者可查看本站专题:《Android开发入门与进阶教程》、《Android视图View技巧总结》、《Android编程之activity操作技巧总结》、《Android数据库操作技巧总结》、《Android资源操作技巧汇总》及《Android控件用法总结》
希望本文所述对大家Android程序设计有所帮助。
热门推荐
10 小红书平安祝福语简短
11 生日祝福语大全女孩简短
12 收生日红包祝福语 简短
13 领证幽默祝福语简短
14 法考面试祝福语简短
15 老哥出门祝福语简短语
16 送灯祝福语简短独特
17 幼儿狗年祝福语大全简短
18 好听的元旦简短祝福语