在代码中设置Button的disabledBackground和disabledTextColor属性,即可指定Button被禁用时的背景和文本颜色。示例代码如下:
Button myButton = findViewById(R.id.my_button); myButton.setEnabled(false); // 将Button禁用 myButton.setDisabledBackground(getResources().getColor(R.color.disabled_button_background)); // 设置禁用时的背景颜色 myButton.setDisabledTextColor(getResources().getColor(R.color.disabled_button_text)); // 设置禁用时的文本颜色