android - 如何删除 EditText 可绘制填充?

标签 android android-layout android-edittext

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

我想要的只是将输入与其余内容对齐,就像美丽的 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——文本移动了但线条保持原样。奇怪的是,我找不到关于这个问题的任何信息,就好像没有人注意到一样。

最佳答案

我认为该行是 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"/>

关于android - 如何删除 EditText 可绘制填充?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29312210/

相关文章:

Android - 无法使用编辑文本字符串的过滤结果更新 ListView

android - setText 在 android 中不起作用

android - 使用 CursorAdapter 相对于 CustomAdapter 的优势

android - 在 Android 的 DrawerLayout 中设置状态栏颜色

Android 动态创建的表 - 性能不佳

android - 根据Android中EditText中的文本启用和禁用Button

android - 来自编辑文本字段的通知内容文本

android - css max-device-width 800 与安卓手机不匹配

java - android中的编辑文本可以允许用户不编辑其第一行吗

android - Intent.ACTION_PICK 为某些联系人返回空光标