我只是想知道是否有一种方法来改变背景图片的不透明度为查看
(即的TextView
,等等)。
I was just wondering if there was a way to change the opacity of the background image for a View
(ie. TextView
, etc.).
我知道我可以设置背景图片是这样的:
I know that I can set the background image like this:
android:background="@drawable/my_drawable_image"
或者,我可以设置一个特定的背景颜色与这样的Alpha设置:
Or I can set a specific background colour with an alpha setting like this:
android:background="#10f7f7f7"
有没有一种方法可以让我控制不透明度(设置alpha),如果我设置背景为绘制的图像?我想这样做在XML布局。我已经知道我可以抓住可绘制对象编程设置alpha,但我想看看我是否能在布局中做到这一点。
Is there a way I can control the opacity (set the alpha) if I'm setting the background as a drawable image? And I want to do this in the XML Layout. I already know that I could grab the Drawable object and programmatically set the alpha, but I want to see if I can do it in the layout.
我最终只是去与的程序化解决方案,因为它看起来并不像它可以通过XML布局来完成。
I ended up just going with the programmatical solution, since it doesn't look like it can be done via the XML layouts.
Drawable rightArrow = getResources().getDrawable(R.drawable.green_arrow_right_small);
// setting the opacity (alpha)
rightArrow.setAlpha(10);
// setting the images on the ImageViews
rightImage.setImageDrawable(rightArrow);