3

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?

Silverstorm
  • 15,398
  • 2
  • 38
  • 52
  • What do you mean by semi-transparent Image button. Did you check documentation for using .ninePatch image files in android? – Wesley Jun 03 '12 at 16:12
  • I mean a ImageButton where the transparency levels can be set for all the background at a determinate level and not only in the empty areas of a png. – Silverstorm Jun 03 '12 at 16:18
  • Are you talking about setting the transparency level by code/xml or by design? – Wesley Jun 03 '12 at 16:20

3 Answers3

2

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);

Wesley
  • 1,808
  • 5
  • 31
  • 46
1

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"
  />
ROHIT PARMAR
  • 901
  • 15
  • 26
0

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)
Eli
  • 707
  • 8
  • 16