I am using TextInputLayout with AppCompatEditText having a custom xml shape based background for AppCompatEditText. Whenever i set some error , the error line starts from beginning of layout. Is there any way to give padding to that error line.
Asked
Active
Viewed 7,665 times
8
-
refer http://stackoverflow.com/questions/32609710/textinputlayout-how-to-give-padding-or-margin-to-hint – sasikumar Jan 21 '16 at 07:26
-
Could you update this question with code that you tried? – Kae10 Jan 21 '16 at 07:26
-
Using `setError(null)` – BST Kaal Jan 21 '16 at 07:37
-
Remove background image to EditText it solve your problem background image to the EditText Creat this problem – Mahesh Suthar Feb 17 '16 at 10:51
3 Answers
6
You can reference error TextView by using:
TextView textView = (TextView) inputLayout.findViewById(android.support.design.R.id
.textinput_error);
Then you can get its layout params to work with.

Boris Kozyrev
- 152
- 1
- 5
-
1risky hack is risky. at the same time tho, I don't think the id would change anytime soon – Aba May 20 '18 at 11:03
-
Keep in mind that the error text view is created only when error is displayed, so you need to change params after you display an error in your TextInputLayout. – Almighty May 22 '19 at 20:11
2
I struggled to solve this and this is what worked for me:
Removing the padding on the parent of the parent of my error textview
Using this solution I could find the error textview (cause I needed to add an icon to it) but couldn´t get rid of the padding, so after a few tries I realized that TextInputLayout has 2 childs so removing the padding from the second child did the trick and just to be sure, I removed it also from the first one
Using Kotlin extensions I came up with a clean solution
/**
* TextInputLayout
*/
fun TextInputLayout.removePadding() {
for (i in 0 until this.childCount) {
this.getChildAt(i).setPadding(0)
}
}
You can do it also in java using the same logic.

Dharman
- 30,962
- 25
- 85
- 135

einschneidend
- 114
- 8
0
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:id="@+id/tx_in_username"
android:errorEnabled="true"
android:layout_marginLeft="@dimen/margin_LEFT_RIGHT"
android:layout_marginRight="@dimen/margin_LEFT_RIGHT"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_marginTop="10dp"
android:layout_height="36sp"
android:hint="Username"
/>

Mallikarjuna
- 874
- 6
- 17