简体   繁体   中英

How to decrease margin and padding of editText programmatically (android)

I have editText which by default leaves lots of space. I added backgroud for textView, cause editText backgroud is not possible.

在此处输入图片说明

When I execute command: editText.setHeight(50); of no matter what integer it gives me same result:

在此处输入图片说明

My text gets cropped. I think somehow I need to reduce editText margins to fit my text here.

Main problem is that there is to much space between rows in first picture.

You can do like this

        int reducedValue =5;

        editText .setPadding(editText .getPaddingLeft()-reducedValue,
                editText .getPaddingTop()-reducedValue,
                editText .getPaddingRight()-reducedValue,
                editText .getPaddingBottom()-reducedValue);

        editText.setCompoundDrawablesWithIntrinsicBounds(editText .getPaddingLeft()-reducedValue,
                editText .getPaddingTop()-reducedValue,
                editText .getPaddingRight()-reducedValue,
                editText .getPaddingBottom()-reducedValue);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM