简体   繁体   中英

how to set transparent background to android tab widget,

Is it possible to set a transparent background to android tab widget,I used the below code to set the tab background image

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

此背景图片的顶部透明

but the problem,is i can see a black line not a transparent, can someone help me on to fix this..!

在此处输入图片说明

There are two things you need to know here.

First, you set a background programmatically with

  • setBackgroundColor(int) (if you're setting it to a color)
  • setBackgroundDrawable(Drawable) (if you're setting it to a Drawable type; this is deprecated, and was replaced by .setBackground(Drawable))
  • setBackgroundResource(int) (for setting a resource from R.java)

Second, you set transparency with the alpha channel of a hex value. Eg. if you want to set your background to red with 20% transparency, you would use the hex value #CCFF0000 . In this example, CC is the hex number for 255 * 0.8 = 204.

I'm a little confused as to what you're trying to achieve here as I can't tell whether drawable is created from an XML file or from an image file. If bgImage is an XML file, however, you should be able to solve your problem by applying the type of hex value I described above to the appropriate area of your XML file with android:background=""

create a transparent png image, just a blank image. Make this image the background for the bar.

mTabHost.getTabWidget().setBackgroundDrawable(R.id.mytransperentimage);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM