View的foreground属性

View有一个foreground属性,这个属性用来设置布局的前景色。

case R.styleable.View_foreground:
           if (targetSdkVersion >= VERSION_CODES.M || this instanceof FrameLayout) {
               setForeground(a.getDrawable(attr));
             }
             break;

当Android版本大于 M 即6.0时,或者当前布局为FrameLayout时,使用foreground才会生效。

关于Google为什么做,我还是不得而知。 foreground属性通常用于给一些布局,主要是帧布局设置一个半透明的前景色,以达到特定的效果,比如,CardView就需要使用foreground属性设置点击的波纹效果。

最后更新于