Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a part of text clickable like button in Android?

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.

like image 449
Karthik Avatar asked Jan 31 '12 08:01

Karthik


People also ask

How do I make part of a text clickable on Android?

In Android, the most common way to show a text is by TextView element. The whole text in the TextView is easy to make clickable implementing the onClick attribute or by setting an onClickListener to the TextView.

How do you make a clickable text Spannable Android?

SpannableString string = new SpannableString("Text with clickable text"); string. setSpan(new CustomClickableSpan(), 10, 19, Spanned. SPAN_EXCLUSIVE_EXCLUSIVE); Text with ClickableSpan .

How do I make a text view clickable?

Just like Buttons and ImageViews we can add onClickListeners to TextViews by simply adding the attribute android:onClick="myMethod" to your TextView XML tag. The other way, TextView tv = (TextView) this.


2 Answers

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.

like image 200
Arun Badole Avatar answered Sep 21 '22 17:09

Arun Badole


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" />
like image 39
J. Gobet Avatar answered Sep 19 '22 17:09

J. Gobet