android - 如何在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());
如果您在理解如何获得颜色时遇到任何困难,如果您有多状态颜色 ColorStateList
,请访问此以获得更清晰的理解。
推荐阅读
- r - 列出所有 shell 函数,不包括以一个或两个下划线开头的私有函数(例如“_func”或“__func”)
- reactjs - 是否有基于 Material UI 的树选择组件?
- python - brotli 如何在 INT64 上实现比 INT32 更好的 parquet 文件压缩?
- css - 如何使具有最大宽度的水平拉伸网格项目居中
- ios - 在 Notification Service 和应用程序之间使用 iOS App Group 容器共享文件(颤振)
- php - 在 WooCommerce 中自动处理已付款订单而不是自动完成
- react-native - React Native TopTabNavigator 图标未显示
- angular - 我如何以自己的方式设计 Angular 10 Material Select(和其他)
- matrix - 如何检查矩阵中的 undef 值(在 Julia 中)并分配一个新值?
- sql - 如何在 postgres jsonb 列中搜索特定的键值?