作者:双眼皮的猪猪2012 | 来源:互联网 | 2023-05-29 14:53
1:activity_main.xml
xmlns:tools="http://schemas.android.com/tools"
android:layout_
android:layout_>
android:id="@+id/tv_show_next_activity"
android:layout_
android:layout_/>
2:MainActivity.java
public class MainActivity extends Activity {
private TextView tvNextActivity=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvNextActivity=(TextView)findViewById(R.id.tv_show_next_activity);
String info="Next activity";
SpannableString sps=new SpannableString(info);
//对字符串拆分并注册点击事件
sps.setSpan(new ClickableSpan(){
public void onClick(View view){
Intent intent=new Intent(MainActivity.this,NextActivity.class);
startActivity(intent);
}
}, 0, info.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
tvNextActivity.setText(sps);
tvNextActivity.setMovementMethod(LinkMovementMethod.getInstance());
}
}
3:运行结果: