Android 自定义TextView可点击区域跟点击处理
private class CustomizedClickableSpan extends ClickableSpan { String text; public CustomizedClickableSpan(String text) { super(); this.text = text; } @Override public void updateDrawState(TextPaint ds) {// ds.setColor(ds.linkColor); ds.setColor(Color.GREEN);// ds.setUnderlineText(false); ds.setAlpha(50); } @Override public void onClick(View widget) { Toast.makeText(ClipboardTestActivity.this, text, Toast.LENGTH_SHORT).show(); }}
测试代码:
TextView textView03 = (TextView) findViewById(R.id.textView3); String str = "AAAAAAAAAAAAAAA"; SpannableString spStr = new SpannableString(str); ClickableSpan clickSpan = new CustomizedClickableSpan(str); spStr.setSpan(clickSpan, 0, str.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); textView03.setText("CCCC"); textView03.append(spStr); textView03.append("BBBB"); textView03.setMovementMethod(LinkMovementMethod.getInstance());
?http://www.myexception.cn/android/1172814.html
?