EditText material construct adds incorrect 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 image on a pre-Lollipop as well as a Lollipop device.
How can I compensate for unnecessary filling EditText

?
I would add android:paddingLeft

to denote a TextView, but I don’t know what value I should specify.

enter image description here

+3


source to share


2 answers


Theme.AppCompat

uses @drawable/abc_edit_text_material.xml

as background EditText

. From sources I can see what it is InsetDrawable

. InsetDrawable

has its own "paddings" - @dimen/abc_control_inset_material

. To compensate for these spacers, I add android:paddingLeft="@dimen/abc_control_inset_material"

to the notch 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 if this is the definitive answer because it is not documented.

+2


source


Create several dimens.xml files with different values ​​- XY folders, where XY is the API level, i.e 18

. : .

The actual values ​​are taken from this file: android:paddingRight="@dimen/...




If you want to use the default API level values, then:

In the SDK folder for each API level, you will find the file size in the values ​​folder.
Take each of these files and copy them into your folders with different meanings.

0


source







All Articles