Skip to content
Advertisement

Inserting imageview inside edittext android

I want to place imageview inside edittext. Would it be possible? I checked “evernote” application, and it was able to put photo on the edittext part. I want to make my application exactly as same. How would I be able to put imageview that was chosen from the gallery, and place the photo inside edittext?

I first tried to put imageview inside relativelayout in .xml file, but it threw me a error sign.

Should I do on .xml file? Or should I make my own edittext java file in order to do that?

Advertisement

Answer

Use this:

<EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/edit_text"
        android:drawablePadding="8dp"
        android:drawableRight="@drawable/yourImage"/>

you can use drawable left,right,top or bottom of your text according to your need.

To manipulate in java use this:

EditText editText = (EditText) findViewById(R.id.yourEditTextId);
editText.setCompoundDrawablesWithIntrinsicBounds(left,top,right,bottom);

for manipulating image set on right:

editText.setCompoundDrawablesWithIntrinsicBounds(0,0,R.drawable.yournewimage,0);

similarly you can do it for other cases.

Hope it helps!!!

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement