Search code examples
androidandroid-gui

Android Levelable Semitransparent ImageButton with leveling transparency


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?


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