Question

I want to insert a clickable ImageView/ImageButton at the end of a multiline TextView, similarly to this example:

Text text text text text text text
text text text text text text text
text text text text text text text
text text text text text text text
text text text. | Image |

I was able to implement this using an ImageSpan and ClickableSpan that I added to the TextView, as suggested here and here. This works quite well, however, the ImageSpan doesn't support selector states, so it is impossible to provide the user with a visual feedback when the ImageSpan is focused or pressed (which is quite bad).

Does anybody know perhaps an alternative solution to implement this? Perhaps by using some custom layouts (like a FlowLayout that works with multiline TextViews)?

Thanks!

Was it helpful?

Solution

Just to close this question: I went for the custom span solution as suggested by pskink in https://stackoverflow.com/a/21933957/441370. This worked perfectly fine. Thanks again!

OTHER TIPS

If You dont want click on that Image, Then you can use drawableRight property for EditText..

android:drawableRight="@drawable/icon"

If you want click then use below code.

<EditText
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:hint="Enter search key" />

<ImageButton
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:src="@drawable/search"
    android:layout_centerVertical="true"
    android:layout_margin="5dp"
    android:text="Button"/>

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top