Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 670
Actine Avatar asked Mar 28 '15 00:03

Actine


People also ask

How do I disable Textinputlayout padding?

You can just set the start and end padding on the inner EditText to 0dp. Here's a screenshot with Show Layout Bounds turned on so you can see that the hints go all the way to the edge of the view.

What is drawable padding?

android:drawablePadding is used for space between image and text.

What is includeFontPadding?

You can use android:includeFontPadding="false" to get rid of the default padding in a TextView . Android docs say this about the attribute: Leave enough room for ascenders and descenders instead of using the font ascent and descent strictly.

What is text view?

A TextView displays text to the user and optionally allows them to edit it. A TextView is a complete text editor, however the basic class is configured to not allow editing.

Is there a way to remove the padding in edittext?

Indeed EditText has its own drawable padding which remains even after setting all paddings/margins to zero in xml. To fully remove padding from EditText you have to remove it from its drawable which in fact is InsetDrawable.

What is Android edittext control?

Android EditText Control Drawable : Android EditText Control is a thin veneer over TextView that configures itself to be editable. Its base class is android.widget.

Who can enter text values in edit text control?

User can enter text values in Edit text control. You can configure Android EditText control to accept different values.

How to get user input from edittext in Android?

Add a EditText in activity_main.xml file. Add a Button in activity_main.xml file. Open MainActivity.kt file and set OnClickListner for the button to get the user input from EditText and show the input as Toast message. Used to specify how to align the text like left, right, center, top, etc.


2 Answers

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"/>
like image 142
l-l Avatar answered Oct 22 '22 15:10

l-l


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

like image 33
Quantum_VC Avatar answered Oct 22 '22 13:10

Quantum_VC