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 送给学长毕业祝福语简短