0

我在 TextView 中有一个长文本,例如“你好,你好吗\n这是我的‘第二个活动’。”。我只想将“第二个活动”文本设为可点击。

我在 ScrollView 中使用 TextView 像这样:

<ScrollView android:id="@+id/scrollView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/gold_btn" android:orientation="vertical"><TextView android:id="@+id/text1" android:layout_width="match_parent" android:layout_height="wrap_content" android:textColor="#FFEFFF" android:text="" android:textSize="23sp"/></ScrollView>

并使用 text1.setText("Hello How Are You This Is my Second Activity"); 在代码中设置文本 我想让“第二个活动”文本可点击,当用户点击“第二个活动”文本时,另一个活动将打开。

字符串很长,也有新的行。

4

2 回答 2

1

您应该考虑使用 ClickableSpan

你会在这里找到类似的东西。

如何设置部分文本视图可点击

于 2013-08-29T14:36:49.530 回答
0

添加多个文本视图并将 onclick 放到要单击的文本视图中:

<TextView
    android:id="@+id/text1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text=""
    android:textColor="#FFEFFF"
    android:textSize="23sp"
    android:onClick="doSomething"
     />

有用的链接

于 2013-08-29T14:39:30.803 回答