Removing TextInputLayout extra top padding

You can remove extra space above AppCompatEditText by setting app:hintEnabled="false" to TextInputLayout but it won't display hint until you re-enable that.

For more info goto Android Developer site -TextInputLayout

Checkout below code

<android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:hintEnabled="false">

    <android.support.v7.widget.AppCompatEditText
        android:id="@+id/txt_amount"
        style="@style/EditTextStyle"
        android:hint="@string/hint_amount"
        android:inputType="numberDecimal"/>
</android.support.design.widget.TextInputLayout>

Hope this helpfull..

@Rajesh


You can do it by overriding the default padding style of TextInputStyle, (Material version should be above 1.1.0)

 <style name="CustomInputLayoutPadding" parent="Widget.MaterialComponents.TextInputLayout.FilledBox">
    <item name="boxBackgroundColor">@color/transparent</item>
    <item name="materialThemeOverlay">@style/CustomOverlayFilledPadding</item>
</style>

then

 <style name="CustomeOverlayFilledPadding">
    <item name="editTextStyle">@style/CustomTextInputEditPaddingStyle</item>
</style>

then

   <style name="CustomTextInputEditPaddingStyle" parent="@style/Widget.MaterialComponents.TextInputEditText.FilledBox">
    <item name="android:paddingStart" ns2:ignore="NewApi">2dp</item>
    <item name="android:paddingEnd" ns2:ignore="NewApi">2dp</item>
    <item name="android:paddingLeft">0dp</item>
    <item name="android:paddingRight">2dp</item>
    <item name="android:paddingTop">28dp</item>
    <item name="android:paddingBottom">12dp</item>
</style>

having a structure like this:

<com.google.android.material.textfield.TextInputLayout
                    android:id="@+id/til_project"
                    style="@style/LoginTextInputLayoutStyle"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="center"
                    app:errorEnabled="false">

                    <com.google.android.material.textfield.TextInputEditText
                        android:id="@+id/totalPiecesProduct"
                        android:layout_gravity="center"
                        android:gravity="center"
                        android:padding="0dp"
                        android:textSize="13sp"
                        style="@style/TextInputEditTextStyle"/>

                </com.google.android.material.textfield.TextInputLayout>

the keys are:

app:errorEnabled="false" in TextInputLayout

`android:padding="0dp"` in `TextInputEditText`

before:

enter image description here

after

enter image description here


The accepted answer didn't work for me on version - 1.2.1 so I did some experiments and realized that the padding doesn't actually come from the TextInputLayout, rather it's from TextInputEditText. So first I removed the padding from that, but it looked uneven, so I set custom padding to TextInputEditText and it worked fine. Just add this line android:padding="16dp" to the TextInputEditText replacing 16dp with your desired value.