如何获取 android 中的复选框色调颜色值?

How to get the checkbox tint color value in android?

我已经设置了复选框的色调,代码如下:

checkBox.setButtonTintList(ColorStateList.valueOf(getResources().getColor(R.color.main_green_color)));

现在我想从同一个复选框中获取 色调值。 任何帮助将不胜感激。

因为您刚刚将 单态颜色 插入到 ColorStateList (ColorStateList.valueOf(getResources().getColor(R.color.main_green_color)) 中,所以您可以获得色调颜色通过

checkBox.getButtonTintList().getDefaultColor()

如果你使用多状态彩色 ColorStateList那么你可以通过

得到特定状态对应的颜色
checkBox.getButtonTintList().getColorForState(stateSet,checkBox.getButtonTintList().getDefaultColor());

如果您在使用 multi-state-colored ColorStateList 时发现在理解如何获取颜色方面遇到任何问题,请访问 this 以获得更清晰的理解.