我有這個代碼爲我的方法調用一個EditText,我試圖使用相同的代碼爲TextView,但它不起作用。文本不像EditText那樣變成超鏈接,有人知道爲什麼嗎?Linkify適用於Android中的TextView嗎?
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tv = (TextView) findViewById(R.id.link_view);
// make sure that setText call comes BEFORE Linkify.addLinks call
tv.setText(tv.getText().toString());
Linkify.addLinks(tv, Linkify.WEB_URLS);
}}
這裏的佈局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TableRow>
<TextView
android:id="@+id/link_lbl"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingRight="10dip"
android:text="Link" />
<TextView
android:id="@+id/link_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="google.com" />
</TableRow>
</TableLayout>
這將很好地工作在EditText上,我只需要幫助的TextView
http://developer.android.com/reference/android/text/util/Linkify.html – Raghunandan