Search code examples
buttontextopacitytransparentlevels

Opacity Levels in Android Studio


I’ve searched and I haven’t found a way to get a certain level of transparency in a colored button while the text of the button is 100% visible.

There has been options to get certain levels of transparency in a button, but the text also becomes transparent and that’s not what I want.

Any pointers?


Solution

  • Do do it in code, you can use:

    yourButtonName.getBackground().setAlpha(int alpha)
    

    where alpha is an int between 0 and 255.

    Do do it in XML, you would add something like this to your button attributes:

    android:background="#8000FF00"
    

    This would yield a 50% opaque green color.

    To better understand how we arrive at the code "#8000FF00" , look here.

    :)