Setting padding value for my EditText
s. 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
for 24 api version
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);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With