Android UI-去除SpannableString下划线
2015-10-20 16:05
465 查看
去除SpannableString下划线
第一步:我们要extends ClickableSpan;
[code]import android.text.TextPaint; import android.text.style.ClickableSpan; import android.view.View; /** * Class_name:NoLineCllikcSpan * Class_description: Override the ClickableSpan * class to remove the underline style (the default system uses ClickableSpan to * Create_time: November 26 2012 - 11:39:51 a.m. Change records: * Modifier: LuoZhiPeng * Modifier_time:November 26, 2012 - 11:39:51 a.m. * Version: * Description: */ public class NoLineCllikcSpan extends ClickableSpan { public NoLineCllikcSpan() { super(); } @Override public void updateDrawState(TextPaint ds) { /**set textColor**/ ds.setColor(ds.linkColor); /**Remove the underline**/ ds.setUnderlineText(false); } @Override public void onClick(View widget) { } }
好的,这个类完成了,其中最关键的一句就是ds.setUnderlineText(false); 相必大家看到这里就应该明白为什么了,它做的操作就是把下划线去掉,设置为false。
那如何在实际中使用呢?相必打击还是很困惑的,那我在这里告诉你如何使用:
第二步:
[code]String name = "虎摸"; String message = ":ghju发的方法给呵护g"; SpannableString spanStr = new SpannableString(name + message); /**设置"虎摸"文字的单击事件**/ spanStr.setSpan(new NoLineCllikcSpan() { @Override public void onClick(View widget) { } }, 0, name.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); /** 设置“虎摸”文字的前景色**/ spanStr.setSpan(new ForegroundColorSpan(Color.rgb(90, 185, 203)), 0, name.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
好的,看到这里大家应该明白怎么用的了吧?
看到那个.setSpan(new NoLineClickcSpan(){}) 这里用到了我们开始第一步中用到的那个重写的类。实现了虎摸的颜色值,也实现了虎摸的点击事件!
忘记了这一步,不好意思,加下。
第三步:如何显示到界面上。
这不其实很简单了,只要一个View装着就可以了,一般我们显示文本都是TextView
所以这里也不例外
[code]TextView tv = (TextView)this.findViewByid(R.lzp.tv); tv.setText( name + message);
TextView只要负责显示就可以了!其它什么点击事件都不需要加.
好的,所有的流程已经完成。谢谢,不喜勿喷
相关文章推荐
- WARN TaskSchedulerImpl: Initial job has not accepted any resources; check your cluster uito ensure
- mysql 如何设置自动增长序列 sequence(一)
- 关于Xilium.CefGlue(CEF3) 加载mp4格式失败
- NDK错误 org.gradle.process.internal.ExecException: Process 'command with non-zero exit value 2
- leetcode Permutation Sequence
- 详细整理:UITableView优化技巧
- wcf 远程服务器返回了意外响应: (413) Request Entity Too Large。
- NSURLRequest POST方式请求
- 获取<meta-data>元素的value属性的值
- StringBuilder和StringBuffer区别
- easyui datagrid 诡异的无法显示问题
- 二、通过纯代码创建的UICollectionView的简单使用
- EasyUi Grid以POST方式传送参数绑定
- conn.setAutoCommit(true)和(false)的区别
- Ubuntu中crosstool-ng编译出错:[ERROR] gtype-desc.c:8829:18: error: subscripted value is neither array nor
- Android ui utils-简单实用的Android界面工具
- UE3代码阅读需知
- Druid使用说明
- Easyui 中 Tabsr的常用方法
- easyUI排序问题