实现购物商城的在价格中间打折----SpannableString类

实现购物商城的在价格中间打折—-SpannableString类

参考:http://www.jianshu.com/p/84067ad289d2
SpannableString介绍

     SpannableString其实和String一样,都是一种字符串类型,同样TextView也可以直接设置SpannableString作为显示文本,不同的是SpannableString可以通过使用其方法setSpan方法实现字符串各种形式风格的显示,重要的是可以指定设置的区间,也就是为字符串指定下标区间内的子字符串设置格式。

该类能实现每个字的大小、颜色、背景、点击、下划线、中划线以及超连接等功能;

在此,我只写如何实现中划线,想学习的可以点击参考连接学习

tv = (TextView) findViewById(R.id.tv);

//设置文本内容
        SpannableString spanString=new SpannableString("Android学习手册:¥300,只要¥3");
//设置300中划线
        StrikethroughSpan strike=new StrikethroughSpan();
        spanString.setSpan(strike,13,16,Spanned.SPAN_INCLUSIVE_INCLUSIVE);

//设置300字体颜色
        ForegroundColorSpan foregroundColorSpan=new ForegroundColorSpan(Color.RED);
        spanString.setSpan(foregroundColorSpan,13,16,Spanned.SPAN_INCLUSIVE_INCLUSIVE);
//设置3的字体颜色
        ForegroundColorSpan foregroundColorSpan2=new ForegroundColorSpan(Color.CYAN);
        spanString.setSpan(foregroundColorSpan2,20,21,Spanned.SPAN_INCLUSIVE_INCLUSIVE);

        tv.setText(spanString);

效果
这里写图片描述
so eazy!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值