Question

I need to create a semi-transparent ImageButton but I haven't find a valid way to do this.

How to set a SemiTransparent look and feel with a settable transparency level?

Any suggestion?

Was it helpful?

Solution

You can adjust the button transparency level with this code. mybutton.getBackground().setAlpha(45);

The number 45 value here ranges from 0 - 255

If you are using a .ninePatch.png file you can obviously reduce the opacity of the button via your image editing software and save it and use it in your xml.

Tip: Semi transparent buttons indicate a button is disabled. According to android design guidelines. So use it wisely.

You can set a button disabled by myButton.setEnabled(false);

OTHER TIPS

you can also add 55 or 99 before hashcode to make button semitransparent

<Button
    android:id="@+id/button1"
    android:layout_width="200dp"
    android:layout_height="60dp"
    android:text="select"
    android:background="#99FFFC00"
  />

If your original image is not transparent, your imagebutton image will not be transparent, to create a transparent image using Photoshop:

http://digitalartanddesign.org/45_transparent_png_Dw.htm

  • Tested to be correct on Marshmallow (6.0)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top