How to make a part of text clickable like button i

2020-03-01 20:21发布

I would like to add button myButton to TextView. How to get it in a single line so that it looks like one set of lines. Here is sample of the text to be added

Please press this here to refresh the set of values.

I want to have "here" as clickable button. How can I do it. Any snippet on it would be helpful.

5条回答
一纸荒年 Trace。
2楼-- · 2020-03-01 20:35

Set background of Button as null by android:background="@null" give the same text color as given to other TextView's.

or You can take 3 TextView's and setOnClickListener to middle one.

查看更多
Ridiculous、
3楼-- · 2020-03-01 20:35

Just add below attribute to TextView in XML layout file to make it clickable.

android:clickable="true"

In your Java file add OnClickListener to complete click action on text view.

查看更多
何必那么认真
4楼-- · 2020-03-01 20:44

Set style of Button with borderless android attribut to remove background and border:

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    style="?android:attr/borderlessButtonStyle"
    android:text="here" />
查看更多
够拽才男人
5楼-- · 2020-03-01 20:45

make three textView ex: textView1, textView2 and textView3.

<RelativeLayout android:id="@+id/textLay"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    >

    <TextView android:id="@+id/textView1" android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:text="Please press this"/>

    <TextView android:id="@+id/textView2" android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
         android:text="here" 
        android:layout_toRightOf="@+id/textView1"  />

    <TextView android:id="@+id/textView3" android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
         android:text="to refresh the set of values." 
        android:layout_toRightOf="@+id/textView2"  />

</RelativeLayout>
查看更多
够拽才男人
6楼-- · 2020-03-01 20:50

Add android:clickable="true" and android:onClick="yourclickname" for the TextView in the XML. Then define yourclickname in your activity. This should make your TextView clickable and triggers the specified method when clicked.

查看更多
登录 后发表回答