Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clickable Button (or any View) inside EditText in android

I want to have a Button or a clickable View in my EditText so that I can perform some action on click of it. I was able to put a drawable inside my EditText thanks to Marcosbeirigo for this answer. But, now I want to make it clickable so that I can perform some action on it. I know this is possible as HTC uses buttons inside EditText in their stock sms app as shown in the following image-

Send button in EditText

In my case, the button will be positioned anywhere, can be in the center also. But the main thing is how can I put a button in EditText?

like image 800
Rajkiran Avatar asked May 31 '12 07:05

Rajkiran


People also ask

How do you make EditText not selectable?

EditText editText=(EditText)findViewById(R. id. editText); editText. setTextIsSelectable(false);

What is editable TextView in Android?

A EditText is an overlay over TextView that configures itself to be editable. It is the predefined subclass of TextView that includes rich editing capabilities.


3 Answers

Use RelativeLayout. The Send and Attach buttons are simple Android Buttons and the 32/160 is a TextView. Put the buttons and the textview on the EditText object, play with the layout arrangments and set some right padding to the EditText object so that the text inside it won't go under the buttons.

You don't need any drawable and listening to the click event of the android buttons is not a question anymore. Its absolutely correct

like image 168
papaiatis Avatar answered Oct 23 '22 09:10

papaiatis


Use this , 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>
like image 45
Gauraw Avatar answered Oct 23 '22 09:10

Gauraw


I think you try to search set click event for compound drawable. You can find some solutions here

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

like image 33
Trung Nguyen Avatar answered Oct 23 '22 07:10

Trung Nguyen