android - 删除 Android EditText 上的左侧填充

标签 android android-layout

默认的 EditText 背景似乎在左侧放置了 ~ 4dp 的填充。这会导致与其他小部件不对齐。

我做了一个简单的应用来演示。截图:

Left padding on EditText

布局:

<LinearLayout 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"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:orientation="vertical"
    tools:context=".MainActivity">


    <TextView
        android:background="#00ff00"
        android:text="@string/hello_world"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="HINT"
        android:text="TEXT"
        android:singleLine="true"/>
    <TextView
        android:background="#00ff00"
        android:text="@string/hello_world"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

</LinearLayout>

有没有办法阻止它这样做?

最佳答案

一种解决方法是在两侧使用负边距 (-4dp)

这仅在 EditText 背景与 Layout 背景匹配时有效,并且您在 Layout 的两侧没有任何东西会被 EditText 覆盖

关于android - 删除 Android EditText 上的左侧填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31735291/

相关文章:

java - 在膨胀布局上调用度量时出现空指针异常

android - 强制 ScrollView 和/或 RecyclerViewt 始终可滚动

android - EditText 在 ScrollView 内不可滚动

java - Android openFileInput 无法解析文件路径

java - Android 项目 ID 未解析

android - 如何检查我的项目中使用了哪个 Gradle Android 插件版本?

android - 将 Action Bar 字体和颜色与应用程序匹配

android - 从 Android Studio 中删除应用程序的栏标题

java - 四舍五入(即使之前的计算结果小于 .5)

android - Android中的自定义字体