[英]How to set the background of button programmatically when that is at some of conditions in android?
當文本值小於 1 時,我將更改 android 中按鈕的背景。
btn_minus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int temp = convertStringToInt(text_count.getText().toString());
if (temp != 1){
text_count.setText(temp-1);
} else {
btn_minus.setBackground(R.drawable.ic_circle_gray_minus);
}
}
});
btn_minus 是 Button 的 object。 並且 btn_minus.setBackground 現在不起作用。
使用 setBackgroundResource() function 代替 setBackground()。
使用以下代碼更改按鈕背景顏色:
btn_minus.setBackgroundResource(R.drawable.ic_circle_gray_minus);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.