是的,setBackgroundColor()方法可以用于所有視圖(View)
setBackgroundColor()
例如,如果你想為一個按鈕設置背景顏色,你可以這樣做:
Button button = findViewById(R.id.my_button); button.setBackgroundColor(Color.parseColor("#FFC107"));
這將把ID為my_button的按鈕的背景顏色設置為黃色。
my_button