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