Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EditText leftView image fit the size of the EditText Android

I want to put an Icon inside an EditText so I did like this:

android:drawableLeft="@drawable/search_icon"

The problem is that the image is bigger than the EditText so the EditText becomes bigger in order to fit the image size. What I want is the opposite: The image should resize in order to fit the EditText height, is it possible?

I (desperately) tried with:

android:adjustViewBounds="true"

But obviously it doesn't work.

Is there any way to do so?

like image 858
LS_ Avatar asked Jul 15 '15 08:07

LS_


1 Answers

Try

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#dd80aa"
android:orientation="vertical">

<RelativeLayout
    android:layout_width="363dp"
    android:layout_height="wrap_content">

    <EditText
        android:id="@+id/editText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Enter text here"
        android:marginLeft="50dp"/>

    <ImageView
        android:layout_width="wrap_contenta"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_gravity="right"
        android:src="@android:drawable/ic_menu_search"/>

</RelativeLayout>


</LinearLayout>
like image 188
Sheychan Avatar answered Sep 29 '22 17:09

Sheychan