如何删除 EditText 可绘制填充?

How to remove EditText drawable padding?

我浪费了最后一个小时试图弄清楚如何在一个简单的 EditText 中去掉这个填充:

我想要的只是将输入与其余内容对齐,就像美丽的 design guide 所说的那样。

布局再简单不过了:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context="com.actinarium.tiomantas.SetupChallengeFragment">

    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="16dp"
            android:orientation="vertical">

        <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/new_challenge_name"/>

        <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"

                android:hint="@string/new_challenge_name_hint1"
                android:singleLine="false"/>

    </LinearLayout>

</ScrollView>

我尝试将 EditText 上的填充设置为 0dp — 文本移动了但线条保持原样。奇怪的是,我找不到任何关于这个问题的信息,好像没有人注意到一样。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.actinarium.tiomantas.SetupChallengeFragment">
<LinearLayout
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="wrap_content">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="16dp"
        android:orientation="vertical">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="jhjkhkhkjkljlkjkljlkj"/>

    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

            android:hint="hjhjhjkhjkhjkhkjhoiuyiyirehyiohj"
            android:singleLine="false"/>
    </LinearLayout>
</LinearLayout>
</ScrollView>

尝试为 textView 提供“4dp”的内边距。以便它与 editText 填充相匹配。

我认为该行是 EditText 的背景图像,因此更改填充不会影响它。如果需要,您可以创建一个没有填充的自定义背景可绘制对象。

您可以做的另一个技巧是向 EditText 添加负边距:

        <EditText
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_marginLeft="-4dp"
             android:hint="@string/new_challenge_name_hint1"
             android:singleLine="false"/>