There appears to be left padding automatically added when using a TextInputLayout
to wrap an EditText
as you can see in the screenshot below.
There is no padding added to the EditText
in the layout XML, but when the view is rendered there appears to be left padding on the EditText
. You can see this when comparing the TextView
below the TextInputLayout
.
How do I disable this left padding from being added?
Thank you!
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.
Now you can simply do input. setError(..) for new error and input. setErrorEnabled(false) to remove it.
To change the bottom line color you have to use the attribute: boxStrokeColor . You can also apply these attributes in your layout: <com.
You can just set the start and end padding on the inner EditText to 0dp.
<com.google.android.material.textfield.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <com.google.android.material.textfield.TextInputEditText android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingStart="0dp" android:paddingEnd="0dp" /> </com.google.android.material.textfield.TextInputLayout>
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.
With the TextInputLayout
included in the Material Components Library you can use a custom style to reduce the padding.
Just use something like:
<com.google.android.material.textfield.TextInputLayout .... android:hint="Hint text" style="@style/My.TextInputLayout.FilledBox.Padding" >
Then you can define a custom style for the EditText
using the materialThemeOverlay
attribute:
<style name="My.TextInputLayout.FilledBox.Padding" parent="Widget.MaterialComponents.TextInputLayout.FilledBox"> <item name="materialThemeOverlay">@style/MyThemeOverlayFilledPadding</item> </style> <style name="MyThemeOverlayFilledPadding"> <item name="editTextStyle">@style/MyTextInputEditText_filledBox_padding</item> </style> <style name="MyTextInputEditText_filledBox_padding" parent="@style/Widget.MaterialComponents.TextInputEditText.FilledBox"> <!-- left and right padding --> <item name="android:paddingStart" ns2:ignore="NewApi">2dp</item> <item name="android:paddingEnd" ns2:ignore="NewApi">2dp</item> <item name="android:paddingLeft">2dp</item> <item name="android:paddingRight">2dp</item> <!-- top and bottom padding --> <item name="android:paddingTop">28dp</item> <item name="android:paddingBottom">12dp</item> </style>
Here the final result:
Note: it requires at least the version 1.1.0 of the Material Components library.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With