publicvoidsetBackgroundDrawable (Drawable background)
Added in API level 1
This method was deprecated in API level 16. use setBackground(Drawable) instead
publicvoidsetBackground (Drawable background)
Added in API level 16
Set the background to a given Drawable, or remove the background. If the background has padding, this View's padding isset to the background's padding. However, when a background is removed, this View's padding isn't touched. If setting the padding is desired, please use setPadding(int, int, int, int).
在再次设置背景前,需要先获取padding,如下:
int paddingLeft = button.getPaddingLeft();
int paddingRight = button.getPaddingRight();
int paddingTop = button.getPaddingTop();
int paddingBottom = button.getBottom();
button.setBackgroundDrawable(new ColorDrawable());
button.setPadding(paddingLeft,paddingTop,paddingRight, paddingBottom);
2016-9-231.view移除背景后再设置背景导致padding无效public void setBackgroundDrawable (Drawable background)Added in API level 1This method was deprecated in API level 16. use setBackground(Drawable) insteadpublic vo