Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android EditText with icon/button

How can I obtain an EditText as those bellow?

enter image description here

The x button removes the text inserted and the eye button displays the clear password as long as it's pressed. Note that I refer to them as buttons because I don't really know what they actually are nor if they are part of the EditText itself or if they are independent views.

like image 801
Ionut Ciuta Avatar asked Feb 09 '16 10:02

Ionut Ciuta


2 Answers

You can just add a button at the right of your EditText

<FrameLayout
    android:id="@+id/layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    style="@style/ScreenLoginContainer">

    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <EditText
            android:id="@+id/edit_text_password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textPassword"
            android:imeOptions="actionDone"
            android:hint="@string/enter_password_hint"
            android:paddingRight="30dp"
            style="@style/ScreenPasswordEditText"/>

    </android.support.design.widget.TextInputLayout>

    <Button
        android:id="@+screen_card_ean_enter/show_password_button"
        style="@style/ShowHidePasswordButton"/>

</FrameLayout>
like image 127
Vasily Kabunov Avatar answered Sep 23 '22 20:09

Vasily Kabunov


You can use android:drawableRight

Set a Drawable to the right of the text, in EditText, in XML .

android:drawableRight="@drawable/Your_drawable"
like image 43
IntelliJ Amiya Avatar answered Sep 23 '22 20:09

IntelliJ Amiya