我有塔伊到新的状态添加到RelativeLayout的,但onCreateDrawableState方法不会被调用。
我的类是:
public class UnreadableRelativeLayout extends RelativeLayout
{
private static final int[] STATE_UNREADED = {R.attr.state_unreaded};
private boolean isUnreaded = false;
public UnreadableRelativeLayout(Context context)
{
super(context);
}
public UnreadableRelativeLayout(Context context, AttributeSet attrs)
{
super(context, attrs);
}
public UnreadableRelativeLayout(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
}
public void setUnreaded(boolean isUnreaded)
{
if (this.isUnreaded != isUnreaded)
{
this.isUnreaded = isUnreaded;
refreshDrawableState();
}
}
@Override
protected int[] onCreateDrawableState(int extraSpace)
{
final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
if (isUnreaded) mergeDrawableStates(drawableState, STATE_UNREADED);
return drawableState;
}
}
为什么onCreateDrawableState方法从来没有打电话?