当点击复选框时,会触发默认的Android材料设计动画(从空白到“V”标记,从“V”标记到空白)。
我想要在动画结束时进行识别。
根据文档,有两种可能的方式 -
当复选框被选中或取消选中(
setOnCheckedChangeListener()
),获取当前的Animation对象(getAnimation()
)并在其上注册一个监听器(setAnimationListener()
)。不幸的是,这并不起作用 - 此时,Animation对象为空。子类化Checkbox对象并实现它的
onAnimationEnd()
方法。遗憾的是,这也不起作用 - 这个方法从来没有被调用过。
我错过了什么?有什么好方法可以识别这样的默认动画何时结束?我认为相关事件可以在活动中的其他视图上进行注册,但我无法弄清楚哪些视图。
这是第一种方法的相关代码片段(animation总是null
) -
CheckBox checkBox = (CheckBox)findViewById(R.id.checkbox1);
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
Animation animation = compoundButton.getAnimation();
Log.d("Checkbox", "Animation is " + animation);
}
});