2

我有一个自定义 ViewGroup,它只做一件事,在布局阶段更改背景的 alpha:

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
        ...
        getBackground().setAlpha(0);
        ...
}

打印阿尔法setBackground

@Override
public void setBackground(Drawable background) {
    if (background instanceof ColorDrawable) {           
        bgAlpha = Color.alpha(((ColorDrawable) background).getColor());
        d("bg:" + Integer.toHexString(bgAlpha));
        super.setBackground(background);
    } else {
       ...
    }
}

现在我有一个活动从布局 xml 扩展这个自定义视图:

   <CustomViewGroup
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#88000000" />

当我第一次启动应用程序时,setBackground打印:

bg:88

然后我完成应用程序并从启动器重新打开它,setBackground打印:

bg:0

为什么活动完成后背景可绘制保持其状态?

4

0 回答 0