转载请标明出处:一片枫叶的专栏
新版本一个需求在用户界面上需要显示中文金额符号“¥”,结果这个字符在有的android手机上显示一个横杠,在有的手机上显示两个横杠,这是因为不同的android手机自带的系统字体是不一致的,因此这个金额符号显示的可能也不一致,这种需求有几种方式:
(1)不管他(就是直接根据系统自带的字体来显示是一个横杠的就显示一个横杠,是两个横杠的就显示两个横杠,问题不是很大,前提是你的产品经理比较好说话。。。)
(2)使用图片的方式(让美工做一张金额符号的图片,这样就保持了显示界面的统一)
(3)复制“¥”使用这个字符
(4)自定义组件,使用自带的字体(统一金额符号的显示)
public class MoneyTextView extends TextView{
private static volatile Typeface moneyFont;
public MoneyTextView(Context context) {
this(context, null);
}
public MoneyTextView(Context context, AttributeSet attrs){
super(context, attrs);
setCustomFont(context);
}
private void setCustomFont(Context context) {
if(moneyFont == null){
synchronized(MoneyTextView.class){
if(moneyFont == null){
AssetManager assertMgr = context.getAssets();
moneyFont = Typeface.createFromAsset(assertMgr, "fonts/money.otf");
}
}
}
setTypeface(moneyFont);
}
}
以上各种方式各有优劣,可以根据具体的情况选择不同的方式。