如何更改 TextInputEditText 中 drawable 的位置?

How can I change the position of drawable in TextInputEditText?

我在具有属性 android:drawableStart 的 TextInputEditText 中设置了一个可绘制对象,它看起来像这样:

drawable default

但实际上,我需要这样说:

The drawable in the way I want

xml 中似乎没有属性可以执行此操作,我查看了属性,似乎没有任何内容符合我的要求。 此外,我一直在互联网上寻找一段时间,但我没有获得实现此目标所需的信息。 有什么想法吗???

在网上不断搜索后,我终于找到了解决办法。首先在这个 ,它在接受的答案中建议,不可能将图标放在顶部,但是,您必须将 EditText 包装在 LinearLayout 中,然后他将 下面的示例代码:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="@android:drawable/edit_text"
android:orientation="horizontal">

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:src="@android:drawable/ic_menu_send"
    android:scaleType="fitStart"
    android:contentDescription="message icon"
    />

<EditText
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:background="@null"
    android:padding="4dp"
    android:text="Message"
    android:inputType="textMultiLine"
    android:gravity="top"
    android:layout_weight="1" />

我采纳了这个想法,并通过将 TextInputLayout 中的图标与包裹在 LinearLayout 中的 FrameLayout 重叠来实现。我的代码如下所示:

        <LinearLayout
        android:layout_marginTop="28dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <FrameLayout
            android:background="@drawable/edt_bg_selector_fafa_orange"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="start">

            <com.google.android.material.textfield.TextInputLayout
                android:id="@+id/tilComentReporte"
                android:gravity="top|start"
                app:errorTextColor="@color/colorRojo"
                app:errorEnabled="true"
                android:maxLines="10"
                android:background="@drawable/edt_bg_selector_fafa_orange"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/etComentReporte"
                    android:paddingBottom="10dp"
                    android:background="@null"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:lines="5"
                    android:gravity="top|start"
                    android:singleLine="false"
                    android:inputType="textMultiLine|textAutoComplete"
                    android:drawablePadding="15dp"
                    android:fontFamily="@font/lato"
                    android:hint="@string/sign_describe_tu_problema"
                    android:paddingStart="20dp"
                    android:textSize="16sp" />
            </com.google.android.material.textfield.TextInputLayout>

            <ImageView
                android:paddingTop="10dp"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:scaleType="fitStart"
                android:src="@drawable/ic_contacto_nar" />
        </FrameLayout>
    </LinearLayout>

在设备上看起来像这样:

The view now