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程序设计有所帮助。
热门推荐
3 祝福语简短的微信
10 幼儿祝福语大全简短贺卡
11 感谢教官文案祝福语简短
12 鼠年同事祝福语简短创意
13 元旦祝福语 简短独特群发
14 妈咪跟我生日祝福语简短
15 给儿子新婚祝福语简短
16 伴娘祝福语长文案简短
17 恭喜高考完祝福语简短
18 生日祝福语送老公简短