如何从当前主题的自定义布尔属性中获取布尔值?
How to get boolean from custom boolean attribute for current theme?
我正在我的主题中设置布尔格式的自定义属性。
<attr name="isCompound" format="boolean" />
当我尝试使用以下
在我的代码中检索此属性时
TypedValue typedValue = new TypedValue();
getTheme().resolveAttribute(R.attr.isCompound, typedValue, true);
if(typedValue.data) {
...
}
我收到错误提示 typedValue.data (int) 无法转换为布尔值。我的问题是如何从当前主题中获取布尔值 isCompound?
感谢@Mike M. 的评论
Blockquote "The data field holds 0 or 1 that was originally specified as "false" or "true"." – https://developer.android.com/reference/android/util/TypedValue#TYPE_INT_BOOLEAN
文档说 returns 1 表示真,0 表示假。但是当我测试它时 returns -1 为真,0 为假。
我猜,安全的方法是检查 false。
我正在我的主题中设置布尔格式的自定义属性。
<attr name="isCompound" format="boolean" />
当我尝试使用以下
在我的代码中检索此属性时TypedValue typedValue = new TypedValue();
getTheme().resolveAttribute(R.attr.isCompound, typedValue, true);
if(typedValue.data) {
...
}
我收到错误提示 typedValue.data (int) 无法转换为布尔值。我的问题是如何从当前主题中获取布尔值 isCompound?
感谢@Mike M. 的评论
Blockquote "The data field holds 0 or 1 that was originally specified as "false" or "true"." – https://developer.android.com/reference/android/util/TypedValue#TYPE_INT_BOOLEAN
文档说 returns 1 表示真,0 表示假。但是当我测试它时 returns -1 为真,0 为假。
我猜,安全的方法是检查 false。