'Padding between divider line and error text in TextInputLayout
How can I set the padding between the divider line
and the error text
(marked with the question mark in the image) in a TextInputLayout
? I tried adding the padding in the style specified as errorTextAppearance
but it had no effect.
EDIT: Here's the layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="test.textinputlayouttest.MainActivity">
<android.support.design.widget.TextInputLayout
android:id="@+id/address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:errorEnabled="true"
app:errorTextAppearance="@style/Error">
<EditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter address"
android:inputType="textEmailAddress"
android:padding="26dp"/>
</android.support.design.widget.TextInputLayout>
</android.support.constraint.ConstraintLayout>
and the style:
<style name="Error" parent="TextAppearance.AppCompat">
<item name="android:textColor">@color/red</item>
<item name="android:paddingBottom">300dp</item>
</style>
Solution 1:[1]
You can get the error textview with
TextView textView = (TextView) inputLayout.findViewById(android.support.design.R.id.textinput_error);
And modify the layout params.
Solution 2:[2]
Just try this way.. I think this will work..
<android.support.design.widget.TextInputLayout
android:id="@+id/usernameWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:padding="26dp"
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:hint="Username"/>
</android.support.design.widget.TextInputLayout>
Solution 3:[3]
Use android:layout_marginBottom="-10dp"
in inner EditText
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.textfield.TextInputLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/textInputLayout"
style="@style/Widget.Design.TextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="-10dp"
tools:text="Text"
/>
</com.google.android.material.textfield.TextInputLayout>
works for version: com.google.android.material:material:1.5.0
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | beeb |
Solution 2 | Tapesh Gupta |
Solution 3 | Vouskopes |