Android中为TextView中的部分文字设置颜色和点击事件
来源:互联网 发布:数据库面试题及答案 编辑:程序博客网 时间:2024/04/28 01:37
text_click = getString(R.string.choose_monitor_text_click);text_phone_content = getString(R.string.choose_monitor_text_phone) + text_click;text_headPad_content = getString(R.string.choose_monitor_text_headpad) + text_click;int start_phoneContent = getString(R.string.choose_monitor_text_phone).length();int end_phoneContent = text_phone_content.length();int start_headPadContent = getString(R.string.choose_monitor_text_headpad).length();int end_headPadContent = text_headPad_content.length();SpannableStringBuilder builder_phone = new SpannableStringBuilder(text_phone_content);SpannableStringBuilder builder_headPad = new SpannableStringBuilder(text_headPad_content);builder_phone.setSpan(new ClickableSpan() {@Overridepublic void updateDrawState(TextPaint ds) {// TODO Auto-generated method stubsuper.updateDrawState(ds);ds.setUnderlineText(false);}@Overridepublic void onClick(View widget) {// TODO Auto-generated method stubtext_phone.setHighlightColor(getResources().getColor(android.R.color.transparent));Intent intent = new Intent(context, SleepexplainActivity.class);startActivity(intent);overridePendingTransition(R.anim.in_righttoleft, R.anim.out_righttoleft);}}, start_phoneContent, end_phoneContent, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);builder_headPad.setSpan(new ClickableSpan() {@Overridepublic void updateDrawState(TextPaint ds) {// TODO Auto-generated method stubsuper.updateDrawState(ds);ds.setUnderlineText(false);}@Overridepublic void onClick(View widget) {// TODO Auto-generated method stubtext_headPad.setHighlightColor(getResources().getColor(android.R.color.transparent));Intent intent = new Intent(context, SleepExplain4HeadPadActivity.class);startActivity(intent);overridePendingTransition(R.anim.in_righttoleft, R.anim.out_righttoleft);}}, start_headPadContent, end_headPadContent, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);text_phone.setText(builder_phone);text_phone.setMovementMethod(LinkMovementMethod.getInstance());// 使用ClickableSpan的点击事件要设置这个才有效text_headPad.setText(builder_headPad);text_headPad.setMovementMethod(LinkMovementMethod.getInstance());
0 0
- Android中为TextView中的部分文字设置颜色和点击事件
- Android 关于TextView中,设置指定部分文字改变颜色,和指定部分文字点击事件
- 关于TextView中,设置指定部分文字改变颜色,和指定部分文字点击事件
- TextView设置部分文字颜色和点击事件
- Android 中TextView部分文字颜色、点击跳转设置
- Android 中TextView部分文字颜色、点击跳转设置
- android textview可以设置文字颜色 部分文字点击事件处理
- TextView中的部分文字自定义颜色和点击事件(类似新浪微博带颜色的可点击字体)
- android 为TextView的部分文字设置超链接样式并监听点击事件
- android 为TextView的部分文字设置超链接样式并监听点击事件
- android 给textview部分文字设置点击事件
- android TextView 设置部分文字背景色和文字颜色
- android TextView 设置部分文字背景色和文字颜色
- android TextView 设置部分文字背景色和文字颜色
- Android TextView 设置部分文字背景色和文字颜色
- android TextView 设置部分文字背景色和文字颜色
- Android-TextView设置多种颜色及部分点击事件
- android 中TextView设置部分文字背景色和文字颜色
- linux下mysql的root密码忘记解决方
- innobackupex备份参数之--databases
- 梦中会哭,梦醒心跳的那么快
- 九度 1366 栈的压入弹出序列
- Leetcode#49||Group Anagrams
- Android中为TextView中的部分文字设置颜色和点击事件
- 双向链表类DoubleLink,提供addFirst,addEnd,delete功能
- 10分钟的学习,改变你的程序员生涯
- mac终端初步
- Java数据类型的转换:隐式(自动)转换与强制转换
- AS3写的页面注册登录组件
- [LeetCode] Add Digits
- FZU 2150 Fire Game
- 选择排序法--java实现