DEMO地址:https://github.com/zhaopingfu/LanguageTypeface
Android中多语言切换
在线简体中文转为繁体中文:http://www.vifo.com.cn/fanti/
使用
第一步:准备资源文件
将要显示的资源文件放在对应文件夹的strings.xml中 简体中文:/res/values/strings.xml 繁体中文:/res/values-zh-rTW/strings.xml 英文:/res/values-en/strings.xml
第二步:修改当前语言环境
Resources resources = getResources(); DisplayMetrics dm = resources.getDisplayMetrics(); Configuration config = resources.getConfiguration(); config.locale = Locale.ENGLISH; resources.updateConfiguration(config, dm);
第三步:刷新页面
一般情况下都是默认直接跳到首页,刷新整个app
Intent intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
Android中使用不同的字体格式
百度云地址:/software/字体格式/资源/AndroidFont/字体/
说明
有一些的字体格式文件的后缀名是大写的ttf,这个不可以改,在java文件中引用的时候也要用大写的,否则异常
使用
第一步
将ttf文件导入到Android项目里,放到assets/fonts下,
第二步
TextView textView = findViewById(R.id.textView); // 这里注意ttf的大小写问题 Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts" + File.separator + "xxx.TTF"); textView.setTypeface(typeface);
简体转繁体
第一步
导入jar包 下载地址:https://code.google.com/p/jcc/downloads/list
第二步
try { JChineseConvertor jChineseConvertor = JChineseConvertor.getInstance(); TextView tv = findViewById(R.id.lan_chinese_zw); tv.setText(jChineseConvertor.s2t("召唤师")); } catch (IOException e) { e.printStackTrace(); }