Android TextView文字點擊事件

Android TextView文字點擊事件ide

本文目的:使讀者快速使用(代碼複製便可用)

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()); //設置了這個點擊才能生效
相關文章
相關標籤/搜索