Inserting imageview inside edittext android

前端 未结 3 1657
南旧
南旧 2021-01-17 08:49

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 app

相关标签:
3条回答
  • 2021-01-17 09:08
    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" />

    0 讨论(0)
  • 2021-01-17 09:14

    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);
    
    0 讨论(0)
  • 2021-01-17 09:26

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

    0 讨论(0)
提交回复
热议问题