Drawable修改透明度
<FrameLayout
android:background="#ffffff"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
1、getBackground();一定要设置background,不然报空指针。然后的到Drawable
2、通过drawable.setAlpha(0-255) 0完全透明,255不透明。
当然也可以直接在布局里设置android:alpha="",这个方法也可以0f-1f,但是如果在父布局使用,那么其他的子布局也会跟着透明状态显示。 各有所需。
这设置动态更改透明度完全没有任何问题,但是会存在其他同样背景也会跟着改变
解决方法就是Drawable里面的mutate()方法。 使用该方法,在可变的Drawable上使用此方法将无效。
Drawable drawable = getBackground().mutate();
drawable.setAlpha(0);
点击进入改方法里面,里面有介绍为什么会导致其他同样资源也会跟着改变