Actine
Actine

Reputation: 2917

How to remove EditText drawable padding?

I wasted the last hour trying to figure out how to get rid of this padding in a simple EditText: enter image description here

All I want is to align the input with the rest of the content, just like the beautiful design guide says.

The layout couldn't be simpler:

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

I tried setting padding on EditText to 0dp — the text shifted but the line remained as is. Strangely enough, I could not find ANY info on this issue, as if no one had noticed.

Upvotes: 8

Views: 4227

Answers (3)

l-l
l-l

Reputation: 3854

I think the line is a background image for the EditText so changing the padding won't affect it. If you want you can create a custom background drawable that has no padding.

Another hack you could do is add a negative margin to the 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"/>

Upvotes: 8

Quantum_VC
Quantum_VC

Reputation: 185

Try giving "4dp" of padding for textView. So that it matches with editText padding.

Upvotes: 1

Zeeshan Khan
Zeeshan Khan

Reputation: 563

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

Upvotes: -1

Related Questions