版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/SummerCloudXT/article/details/82804789
在Xml里面修改
app:backgroundTint="@color/yourcolor"
在代码里面修改
//获取方法
private ColorStateList getColorStateListTest(int colorRes) {
int[][] states = new int[][]{
new int[]{android.R.attr.state_enabled}, // enabled
new int[]{-android.R.attr.state_enabled}, // disabled
new int[]{-android.R.attr.state_checked}, // unchecked
new int[]{android.R.attr.state_pressed} // pressed
};
int color = ContextCompat.getColor(context, colorRes);
int[] colors = new int[]{color, color, color, color};
return new ColorStateList(states, colors);
}
//调用方法
mfb.setBackgroundTintList(getColorStateListTest(R.color.yourcolor));
如果还想修改前景色,像这样
faoatBtn.setColorFilter(R.color.yourcolor);