01 | package com.example.wenchen.myapplication; |
03 | import android.support.v7.app.AppCompatActivity; |
04 | import android.os.Bundle; |
05 | import android.content.Intent; |
06 | import android.view.View; |
07 | import android.widget.TextView; |
08 | import android.text.SpannableStringBuilder; |
09 | import android.text.Spanned; |
10 | import android.text.style.URLSpan; |
12 | public class MainActivity extends AppCompatActivity { |
14 | protected void onCreate( Bundle savedInstanceState ) { |
15 | super .onCreate( savedInstanceState ); |
16 | setContentView( R.layout.activity_main ); |
17 | TextView tv = (TextView) findViewById( R.id.txtMsg ); |
18 | MainActivity.makeTextViewHyperlink( tv ); |
19 | tv.setOnClickListener( new View.OnClickListener( ) { |
21 | public void onClick( View v ) { |
22 | Intent intent = new Intent( MainActivity. this , NextActivity. class ); |
23 | startActivity( intent ); |
29 | public static void makeTextViewHyperlink( TextView tv ) { |
30 | SpannableStringBuilder ssb = new SpannableStringBuilder( ); |
31 | ssb.append( tv.getText( ) ); |
32 | ssb.setSpan( new URLSpan( "#" ), 0 , ssb.length(), |
33 | Spanned.SPAN_EXCLUSIVE_EXCLUSIVE ); |
34 | tv.setText( ssb, TextView.BufferType.SPANNABLE ); |
|