Doesn't work EditText padding in the API 21

后端 未结 6 1056
你的背包
你的背包 2021-02-07 21:08

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

6条回答
  •  你的背包
    2021-02-07 22:00

    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);
    }
    

    }

提交回复
热议问题