

image.png

res目录下文件
<string name="search_pathogens">病原体搜索</string>
<string name="pathogens">病原体</string>
<string name="virus">病毒</string>
<string name="bacteria">细菌</string>
<string name="fungus">真菌</string>
<string name="others">其他</string>
<string name="collection">收藏</string>
<string name="search_pathogens">Search for pathogens</string>
<string name="pathogens">Pathogens</string>
<string name="virus">Virus</string>
<string name="bacteria">Bacteria</string>
<string name="fungus">Fungus</string>
<string name="others">Others</string>
<string name="collection">Collection</string>
// 获得res资源对象
Resources resources = activity.getResources();
// 获得屏幕参数:主要是分辨率,像素等。
DisplayMetrics metrics = resources.getDisplayMetrics();
// 获得配置对象
Configuration config = resources.getConfiguration();
//区别17版本(其实在17以上版本通过 config.locale设置也是有效的,不知道为什么还要区别)
//在这里设置需要转换成的语言,也就是选择用哪个values目录下的strings.xml文件
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
config.setLocale(Locale.SIMPLIFIED_CHINESE);//设置简体中文
//config.setLocale(Locale.ENGLISH);//设置英文
} else {
config.locale = Locale.SIMPLIFIED_CHINESE;//设置简体中文
//config.locale = Locale.ENGLISH;//设置英文
}
resources.updateConfiguration(config, metrics);
//调完这个之后,文字就会变成你设置的其他语言了
tvFungus.setText(getResources().getString(R.string.fungus));