1

Possible Duplicate:
Android Labels or Bubbles in EditText

How can i put buttons on EditText like this:

enter image description here

I only find how to put 'X' at the end of EditText, but I couldn't relate how to use this as I want. Of course I'm talking about android.

Community
  • 1
  • 1
Jakub Dyszkiewicz
  • 524
  • 1
  • 5
  • 17

2 Answers2

1

If you want a button to the right of your edittext you could wrap it in a horizontal linear layout like so

<LinearLayout android:orientation="horizontal"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content">

<EditText 
    android:id="@+id/editSearchContact"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"/>

<Button android:id="@+id/xbutton"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"/>
</LinearLayout>

If you want an actual X use image button.

EDIT: Oh and for more control you can use the android:weight="" attribute to give the edit text a ratio of the width of the screen to expand to.

Jack
  • 2,625
  • 5
  • 33
  • 56
1

Another option(if i understood well what you want) is this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <!-- This LinearLayout will be your EditText that holds two Buttons with name and also image-->    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:drawable/editbox_background" >

        <Button
            android:id="@+id/the_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginRight="7dp"
            android:background="@drawable/draw_the_button"
            android:padding="5dp"
            android:text="Name Here" />

        <EditText
            android:id="@+id/editText1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@null"
            android:layout_gravity="center_vertical" />

        <ImageButton
            android:id="@+id/imageButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@null"
            android:src="@android:drawable/ic_input_add"
            android:layout_gravity="center_vertical"  />
    </LinearLayout>

</LinearLayout>

Try it.

user
  • 86,916
  • 18
  • 197
  • 190