-3

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?

justtookoff
  • 11
  • 1
  • 2
  • 2
    use `android:drawableLeft="@drawable/some_icon"` on your `EditText` – shinilms Jul 18 '17 at 10:51
  • Add some more info or code which you have tried. – Wasim K. Memon Jul 18 '17 at 10:57
  • [Check the post if your requirement is like this][1]https://stackoverflow.com/questions/3703283/how-can-i-add-an-image-on-edittext – Logo Jul 18 '17 at 10:58
  • When I put drawable layout, how can I manipulate that drawable thing inside my java file? Moreover, I tested out drawable, the problem was that the image that I put was visible.. I want to make it invisible first, and whenever the client puts the image in, I want to show that image.. Thanks! – justtookoff Jul 18 '17 at 19:25

4 Answers4

5

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!!!

sumit
  • 1,047
  • 1
  • 10
  • 15
  • When I put drawable layout, how can I manipulate that drawable thing inside my java file? Moreover, I tested out drawable, the problem was that the image that I put was visible.. I want to make it invisible first, and whenever the client puts the image in, I want to show that image.. Thanks! – justtookoff Jul 18 '17 at 19:25
1
  1. U Can try this edit text inside image
 <EditText
    android:id="@+id/editText"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:background="@drawable/draw_bor"
    android:drawableLeft="@drawable/icon"
    android:inputType="phone"
    android:hint="enter number"
    android:padding="10dp"
    android:textColorHint="#bbbbbb" />
Ryan M
  • 18,333
  • 31
  • 67
  • 74
Prashant R P
  • 124
  • 12
  • When I put drawable layout, how can I manipulate that drawable thing inside my java file? Moreover, I tested out drawable, the problem was that the image that I put was visible.. I want to make it invisible first, and whenever the client puts the image in, I want to show that image.. Thanks! – justtookoff Jul 18 '17 at 19:25
0

you can use following property of editext to set image in editext

android:drawableTop=""
android:drawableBottom=""
android:drawableRight=""
android:drawableLeft=""
android:drawableEnd=""

like this

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    android:drawableTop="@mipmap/ic_launcher"
    android:drawableBottom="@mipmap/ic_launcher"
    android:drawableRight="@mipmap/ic_launcher"
    android:drawableLeft="@mipmap/ic_launcher"
    android:drawableEnd="@mipmap/ic_launcher"/>

or you can set drabble programatically like this

editText.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.drawableRight, 0);
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
  • When I put drawable layout, how can I manipulate that drawable thing inside my java file? Moreover, I tested out drawable, the problem was that the image that I put was visible.. I want to make it invisible first, and whenever the client puts the image in, I want to show that image.. Thanks! – justtookoff Jul 18 '17 at 19:25
  • @justtookoff check my updated ans and let me know in case of any query – AskNilesh Jul 19 '17 at 04:36
0
<RelativeLayout
            android:id="@+id/passwordLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginHorizontal="@dimen/_15sdp"
            android:layout_marginTop="@dimen/_13sdp"
            android:background="@drawable/new_goal_bg"
            android:padding="@dimen/_10sdp">


            <EditText
                android:id="@+id/pwd"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/_10sdp"
                android:layout_toLeftOf="@+id/plusIc"
                android:background="@null"
                android:fontFamily="@font/poppins_regular"
                android:hint="Enter a New Goal"
                android:inputType="textPersonName"
                android:textColor="@color/view_color"
                android:textColorHint="@color/black"
                android:textSize="@dimen/_11ssp"
                tools:ignore="NotSibling,TouchTargetSizeCheck,TouchTargetSizeCheck" />


            <LinearLayout
                android:id="@+id/plusIc"
                android:layout_width="@dimen/_15sdp"
                android:layout_height="@dimen/_15sdp"
                android:layout_alignParentEnd="true"
                android:layout_centerVertical="true">


                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:src="@drawable/ic_plus" />

            </LinearLayout>

        </RelativeLayout>
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 26 '22 at 17:32