如何设置android tab widget的透明背景,

时间:2013-08-02 14:51:06

标签: android android-tabhost

是否可以设置透明背景到android标签小部件,我使用下面的代码来设置标签背景图像

   Drawable drawable = new BitmapDrawable(bgImage);
    mTabHost.getTabWidget().setBackgroundDrawable(drawable);

this background image has a transparent in top

但问题是,我可以看到黑线不透明,有人可以帮我解决这个问题..!

enter image description here

2 个答案:

答案 0 :(得分:0)

这里有两件事你需要知道。

首先,使用

以编程方式设置背景
  • setBackgroundColor(int)(如果您将其设置为颜色)
  • setBackgroundDrawable(Drawable)(如果您将其设置为Drawable类型;不推荐使用,并替换为.setBackground(Drawable))
  • setBackgroundResource(int)(用于从R.java设置资源)

其次,使用十六进制值的alpha通道设置透明度。例如。如果要将背景设置为红色且透明度为20%,则应使用十六进制值#CCFF0000。在此示例中,CC是255 * 0.8 = 204的十六进制数。

我对你在这里想要实现的目标感到有点困惑,因为我无法判断是否从XML文件或图像文件创建了drawable。但是,如果bgImage是一个XML文件,您应该能够通过使用android:background=""

将上述十六进制值类型应用于XML文件的相应区域来解决您的问题。

答案 1 :(得分:0)

创建一个透明的png图像,只是一个空白图像。使此图像成为条形图的背景。

mTabHost.getTabWidget().setBackgroundDrawable(R.id.mytransperentimage);
相关问题