Android TextView文字点击事件

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

Android TextView文字点击事件

本文目的:使读者快速使用(代码复制即可用)

SpannableString ss = new SpannableString(tip);
        ss.setSpan(new ClickableSpan() {
            @Override
            public void onClick(View widget) {
                //do what you want
            }
 
            @Override
            public void updateDrawState(TextPaint ds) {
                ds.setColor(getResources().getColor(R.color.green_23cc77));//文字颜色
                ds.setUnderlineText(false);//不要下划线(默认有下划线)
            }
        }, startIndex, endIndex, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        TextView continueTip = (TextView) view.findViewById(R.id.tv_tip);
        continueTip.setText(ss);
        continueTip.setMovementMethod(LinkMovementMethod.getInstance()); //设置了这个点击才能生效

转载于:https://my.oschina.net/lichuangnk/blog/1822220

你可能感兴趣的:(Android TextView文字点击事件)