TextView

慢吞吞發表於2017-06-07

TextView執行click功能:

借用SpannableString或SpannableStringBuilder,兩者區別:後者多了修改文字功能

程式碼片段:

TextView tv = (TextView) findViewById(R.id.textview1);
String t = "顯示下個activity";
SpannableString ss = new SpannableString(t);
ss.setSpan(new ClickableSpan() {

@Override
public void onClick(View widget) {
Intent i = new Intent(TextViewActivity.this,CanvasActivity.class);
startActivity(i);

}
}, 0, t.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

tv.setText(ss);
tv.setMovementMethod(LinkMovementMethod.getInstance());

 

 

相關文章