[英]Inserting imageview inside edittext android
I want to place imageview inside edittext.我想将 imageview 放在 edittext 中。 Would it be possible?
可能吗? I checked "evernote" application, and it was able to put photo on the edittext part.
我检查了“evernote”应用程序,它能够将照片放在 edittext 部分。 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?
我怎样才能把从图库中选择的 imageview 放入 edittext 中?
I first tried to put imageview inside relativelayout in.xml file, but it threw me a error sign.我首先尝试将 imageview 放入 relativelayout in.xml 文件中,但它给我一个错误信号。
Should I do on.xml file?我应该做 on.xml 文件吗? Or should I make my own edittext java file in order to do that?
还是我应该制作自己的 edittext java 文件才能做到这一点?
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:要在 java 中操作,请使用以下命令:
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希望能帮助到你
<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" />
you can use following property of editext
to set image in editext您可以使用editext的以下属性在
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或者你可以像这样以编程方式设置 drabble
editText.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.drawableRight, 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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.