Android tips(一)-->Android统一显示¥符号

新版本一个需求在用户界面上需要显示中文金额符号“¥”,结果这个字符在有的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);
    }
}
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

以上各种方式各有优劣,可以根据具体的情况选择不同的方式。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值