首页 > 解决方案 > 如何在android中获取复选框色调颜色值?

问题描述

我已经使用以下代码设置了复选框的色调:

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

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

标签: androidcheckboxcolorstint

解决方案


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

checkBox.getButtonTintList().getDefaultColor()

如果您使用多状态颜色 ColorStateList,那么您可以通过以下方式获得特定状态的对应颜色

checkBox.getButtonTintList().getColorForState(stateSet,checkBox.getButtonTintList().getDefaultColor());

如果您在理解如何获得颜色时遇到任何困难,如果您有多状态颜色 ColorStateList,请访问以获得更清晰的理解。


推荐阅读