视图中背景可绘制图像的不透明度(使用 XML 布局) [英] Opacity on a background Drawable image in View (using XML Layout)

查看:27
本文介绍了视图中背景可绘制图像的不透明度(使用 XML 布局)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道是否有办法更改 View(即 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 布局中做到这一点.我已经知道我可以抓取 Drawable 对象并以编程方式设置 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);

这篇关于视图中背景可绘制图像的不透明度(使用 XML 布局)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆