2023-01-13 Android app java 获取设置控件背景颜色用setBackgroundColor,获取控件背景眼色用getBackground 、.getColor()的形式

一、设置控件背景颜色用setBackgroundColor

mView.findViewById(resId).setBackgroundColor(Color.GREEN);

二、获取控件背景颜色方法

Button button = (Button) findViewById(R.id.my_button);
ColorDrawable buttonColor = (ColorDrawable) button.getBackground();
int colorId = buttonColor.getColor();

三、实际应用,检测所有的控件背景是否都是某一种颜色。

 四、参考文章

获取android中按钮的背景颜色 |

猜你喜欢

转载自blog.csdn.net/qq_37858386/article/details/128677699
今日推荐