Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doesn't work EditText padding in the API 21

Doesn't work EditText padding in the API 21. I try to do it in empty project, only with single editText, but it still doesn't work.

Set padding programmatically works, but in my work project, I've a lot of EditTexts with different paddings and set padding programmatically isn't right way.

On API level 19 xml padding works well.

Are there any solutions?

This my EditText xml code:

   <EditText
   android:id="@+id/et_text"
   android:text="Text"
   android:paddingLeft="20dp"
   android:paddingStart="20dp"
   android:paddingRight="20dp"
   android:paddingEnd="20dp"
   android:layout_marginLeft="30dp"
   android:layout_marginRight="30dp"
   android:layout_width="match_parent"
   android:layout_height="45dp"/>

In the result, I've got:enter image description here

I expect:

enter image description here

like image 710
user3134124 Avatar asked Oct 21 '14 14:10

user3134124


4 Answers

This is android bug. In future it will be fix.

Bug report on google code.

like image 115
user3134124 Avatar answered Nov 07 '22 04:11

user3134124


Solved it by creating a custom edittext with padding and use it in xml.

public class MyEditTextView extends EditText{

public MyEditTextView(Context context) {
    super(context);
    init();
}

public MyEditTextView(Context context, AttributeSet attrs) {
    super(context, attrs);
    init();
}

public MyEditTextView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    init();
}

private void init(){
    int paddingLeftRight = (int) getResources().getDimension(R.dimen.edittext_padding);
    int topPadding = this.getPaddingTop();
    int bottomPadding = this.getPaddingBottom();
    setPadding(paddingLeftRight, topPadding, paddingLeftRight, bottomPadding);
}

}

like image 29
aNoviceGuy Avatar answered Nov 07 '22 03:11

aNoviceGuy


Just replace android:paddingLeft with android:paddingStart, as should be anyway and fixes this bug on those devices.

like image 2
r3flss ExlUtr Avatar answered Nov 07 '22 02:11

r3flss ExlUtr


Try to give padding programmatically by using method setLayoutParams() it will work i am hopeful Ref: Example

like image 1
Intsab Haider Avatar answered Nov 07 '22 02:11

Intsab Haider