Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Material Design EditText adds wrong padding

layout.xml:

<LinearLayout 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"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <TextView android:text="Label text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <EditText
        android:text="Input tex"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

Produces the following picture on pre-Lollipop as well as on Lollipop device.
How can I compensate the unnecessary padding of EditText?
I would add android:paddingLeft to label TextView, but I don't know which value should I specify.

enter image description here

like image 754
Dima Kornilov Avatar asked Aug 27 '26 09:08

Dima Kornilov


1 Answers

Theme.AppCompat uses @drawable/abc_edit_text_material.xml as EditText background. From the sources I see that it is an InsetDrawable. InsetDrawable has it own "paddings" - @dimen/abc_control_inset_material. To compensate these paddings, I add android:paddingLeft="@dimen/abc_control_inset_material" to label's TextView.

<TextView android:text="Label text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingLeft="@dimen/abc_control_inset_material"/>

I'm not sure this is a final answer, because it's not documented.

like image 67
Dima Kornilov Avatar answered Aug 30 '26 00:08

Dima Kornilov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!