Set padding in after setBackgroundResource() reset padding in Android


When we use setBackgroundResource(), it automatically reset some property in our XML. The most common things that happen is padding. We can set padding that changed by setBackgroundResource by :

1
yourView.setPadding(<left>, <top>, <right>, <bottom>);
1
2
search.setBackgroundResource(R.drawable.search_noborder);
search.setPadding(10, 0, 40, 0);

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.