5

Setting padding value for my EditTexts. However It doesn't work both 21 and 22 api versions. However, It works perfectly for 19, 23, 24.

Here is my codes:

<style name="LoginEditTextStyle">
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_gravity">center_horizontal</item>
        <item name="android:maxLines">1</item>
        <item name="android:paddingLeft">@dimen/login_text_padding</item>
        <item name="android:paddingRight">@dimen/login_text_padding</item>
    </style>

This my edittext in the layout xml

<android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
          android:layout_marginTop="@dimen/login_container_child_view_top_margin"
            android:alpha="0">

            <EditText
                android:id="@+id/login_username_editText"
                style="@style/LoginEditTextStyle"
                android:hint="@string/user_name"
                android:inputType="text"
                />

        </android.support.design.widget.TextInputLayout>

The result for 21 api version

enter image description here

for 24 api version

enter image description here

I know there is a bug of edittext/spinner view to set padding value from xml.

I know there is some solution for this issue such as setting padding values programmaticaly. But It doesn't work for me.

for example : this accepted solution doesn't work for me

int paddingLeft = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 40, getResources().getDisplayMetrics());
        int paddingRight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 55, getResources().getDisplayMetrics());
        int paddingTop = editText.getPaddingTop();
        int paddingBottom = editText.getPaddingBottom();
        editText.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
Community
  • 1
  • 1
ziLk
  • 3,120
  • 21
  • 45

1 Answers1

2

I faced the same problem. paddingLeft doesn't work on Android 5.1.1 devices.

Add paddingStart instead which solved the problem for me.

Please give it a try.

clemens
  • 16,716
  • 11
  • 50
  • 65
Allen Wang
  • 31
  • 3