要设置Android按钮的颜色,可以使用以下方法:
- 在XML布局文件中设置按钮的背景颜色:
- 在java代码中设置按钮的背景颜色:
Button button = findViewById(R.id.button); button.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
- 使用Selector设置按钮的不同状态下的颜色: 在res/drawable文件夹下创建一个selector文件,例如button_selector.xml,内容如下:
然后在布局文件或java代码中设置按钮的背景为这个selector:
通过以上方法可以设置Android按钮的颜色。