Clickable button (or any kind) inside EditText in android

I want to have a button or clickable view in my EditText so that I can perform some actions when I click on it. I managed to add Marcosbeirigo EditText to this text for my answer. But now I want to make it clickable so that I can perform some actions on it. I know this is possible since HTC uses buttons inside EditText in its sms application in stock, as shown in the following figure -

Send button in EditText

In my case, the button will be located anywhere, it can also be in the center. But most importantly, how can I put a button in an EditText?

+9
android android-edittext button
source share
6 answers

Use RelativeLayout. The send and attach buttons are simple buttons for Android, and 32/160 is a TextView. Place the buttons and the text image on the EditText object, play with the layout layouts and set the correct addition to the EditText object so that the text inside it does not fall under the buttons.

You don't need portability, and listening for the click event for android buttons is no longer an issue. Its absolutely correct

+9
source share

Use it, it worked for me -

<RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <EditText android:id="@+id/id_search_EditText" android:layout_width="fill_parent" android:layout_height="wrap_content" android:singleLine="true" android:paddingRight="40dp" android:hint="Enter your feelings and connect" /> <ImageButton android:id="@+id/id_search_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@+id/id_search_EditText" android:layout_alignBottom="@+id/id_search_EditText" android:layout_alignRight="@+id/id_search_EditText" android:background="@drawable/ic_launcher"/> </RelativeLayout> 
+5
source share

I think you are trying to search for a click click event for a composite drawable. Here you can find some solutions.

handling-click-events-on-a-drawable-within-an-edittext

+2
source share

there is no button inside editText. This is just an edit text with a white background, so you don’t see its fields and a simple layout layout.

0
source share

The only possible solution is to use RelativeLayout , which will allow you to put Views in overlay to others too. Another layout will not allow you to do such things.

I also found this tutorial: http://developer.android.com/resources/articles/layout-tricks-merge.html , maybe it can help you :)

0
source share

output

Use this code that may work.

 <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <RelativeLayout android:id="@+id/REFReLayTellFriend" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:orientation="horizontal" android:paddingBottom="5dp" android:paddingTop="5dp"> <EditText android:id="@+id/txtSearch" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/editext_rounded" android:drawableLeft="@android:drawable/ic_menu_search" android:gravity="start" android:hint="Search" android:singleLine="true"/> <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignRight="@+id/txtSearch" android:background="@drawable/ic_action_content_filter_list"/> </RelativeLayout> </LinearLayout> 
0
source share

All Articles