簡體   English   中英

在 edittext android 中插入 imageview

[英]Inserting imageview inside edittext android

我想將 imageview 放在 edittext 中。 可能嗎? 我檢查了“evernote”應用程序,它能夠將照片放在 edittext 部分。 我想讓我的申請完全一樣。 我怎樣才能把從圖庫中選擇的 imageview 放入 edittext 中?

我首先嘗試將 imageview 放入 relativelayout in.xml 文件中,但它給我一個錯誤信號。

我應該做 on.xml 文件嗎? 還是我應該制作自己的 edittext java 文件才能做到這一點?

用這個:

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

您可以根據需要使用可繪制的左側、右側、頂部或底部的文本。

要在 java 中操作,請使用以下命令:

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

用於操作右側的圖像集:

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

同樣,您可以在其他情況下這樣做。

希望能幫助到你

  1. 你可以試試這個編輯圖片里面的文字
 <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" />

您可以使用editext的以下屬性在editext中設置圖像

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

像這樣

<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"/>

或者你可以像這樣以編程方式設置 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM