阅读更多
package wq.test;import android.app.Activity;import android.graphics.Color;import android.os.Bundle;import android.text.SpannableString;import android.text.Spanned;import android.text.method.LinkMovementMethod;import android.text.style.ClickableSpan;import android.view.View;import android.widget.TextView;public class AndroidTestActivity extends Activity{private final String stringToShow = "test,test,test,test,test,test,test,test,test,test,test,test," +"test,test,test,test,test,test,test,test,test,test,test,test,test,test" +",test,test,test,test,test,test,test,test,test,test,test,test,test,test" +"testtest test test...";private final String readMore = "Read More";@Overridepublic void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);this.setContentView(R.layout.main);TextView tv = (TextView) this.findViewById(R.id.textView);ClickableSpan clickableSpan = new ClickableSpan() {@Overridepublic void onClick(View widget) {if (widget instanceof TextView) {((TextView) widget).setText(stringToShow + stringToShow);}}};setClickableSpanForTextView(tv, clickableSpan, stringToShow + readMore, stringToShow.length(), stringToShow.length() + readMore.length());}/** *  * @param tv TextView * @param clickableSpan Click event * @param text Text to show * @param start Start point in text for handle click event * @param end End point in text for handle click event */private void setClickableSpanForTextView(TextView tv, ClickableSpan clickableSpan, String text, int start, int end) {SpannableString sp = new SpannableString(text);sp.setSpan(clickableSpan, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);tv.setText(sp);tv.setLinkTextColor(Color.RED);tv.setMovementMethod(LinkMovementMethod.getInstance());tv.setFocusable(false);tv.setClickable(false);tv.setLongClickable(false);}}

更多相关文章

  1. OpenGL ES教程V之更多3D模型(原文对照)
  2. Android从零撸美团(四) - 美团首页布局解析及实现 - Banner+自定
  3. EditText设置更多文字为省略号
  4. 短视频PHP源码Android 打造专属的下拉刷新 加载更多
  5. Android 1.6 支持更多的屏幕大小和分辨率
  6. NestedScrollView+RecyclerView滑动冲突问题,加载更多
  7. Activity生命周期的回调,你应该知道得更多!--Android源码剖析(上)
  8. Android中文文档v0.1 beta低调发布,期待更多同学来参加review
  9. Android公共库——图片缓存 网络缓存 下拉及底部更多ListView 公

随机推荐

  1. android的service中在后台弹出提示框
  2. android中去掉EditText的自动焦点获取
  3. 默认不弹出输入面板
  4. 更新android studio gradle 不成功解决方
  5. 一个简单的Android 自定义view,实现手指
  6. android中处理各种触摸事件
  7. build WebRTC for android
  8. Android开发日记 --(1)Android系统开发环境
  9. Android: Android Resources
  10. Android Studio升级3.2以后 Androidx 异