子控件 childView ,以View为例;
父控件 parantView 以ViewGroup为例;
childView设置了android:duplicateParentState 或 setDuplicateParentStateEnabled 为true
实际上是调用
setFlags(enabled ?DUPLICATE_PARENT_STATE : 0, DUPLICATE_PARENT_STATE);把标志位保存到mViewFlags中.
当 parantView状态改变,比如setSelected 或 setPressed,会调用refreshDrawableState();
public void refreshDrawableState() {
mPrivateFlags |= PFLAG_DRAWABLE_STATE_DIRTY;
drawableStateChanged();
ViewParent parent = mParent;
if (parent !=null) {
parent.childDrawableStateChanged(this);
}
}
可以看到,它里面其实调用了drawableStateChanged();protected void drawableStateChanged() {
super.drawableStateChanged()