我正在尝试在文本框的相邻文本中创建链接。但是,这个链接不是URL,而是一个按钮,这样我就可以在onItemClick事件中执行一些任务。我基本上是将它连接到一个视图,该视图显示了我们的最终用户许可协议(硬编码)。
我如何才能做到这一点呢?
提前谢谢。
发布于 2011-11-18 23:22:49
创建一个不带文本的CheckBox,并在其旁边添加两个TextView。第一个是一个不可点击的视图,带有类似“我已阅读并同意”这样的文本。第二个是一个可点击的视图,带有类似“条款和条件”的文本。将TextView并排放置,不要留出空白处。请注意第一个视图末尾的额外空间,用于自然文本对齐。这样,您就可以根据自己的喜好设置两个文本的样式。
示例xml代码:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<CheckBox
android:id="@+id/terms_check"
android:text=""
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/terms_text"
android:layout_toRightOf="@id/terms_check"
android:text="I have read and agree to the "
android:layout_marginLeft="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/terms_link"
android:layout_toRightOf="@id/terms_text"
android:text="TERMS AND CONDITIONS"
android:textColor="#00f"
android:onClick="onClick"
android:clickable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>然后在代码中添加一个onClick()处理程序。瞧。
public class SignUpActivity extends Activity {
public void onClick(View v) {
...
}
}https://stackoverflow.com/questions/8184597
复制相似问题