I want to make Buttons with different transparency levels in android.I have used \"@android:color/transparent\"
. But it makes the button 100% transparent. I need a
Using XML
If you want to set color and along with that if you want to set transparent then you have to use that color code .
android:color="#66FF0000" // Partially transparent red
android:alpha="0.25" // 25% transparent
Using java
And if you want to set dynamically (java code)then try this,
myButton.getBackground().setAlpha(64); // 25% transparent
- i.e .INT ranges from 0 (fully transparent) to 255 (fully opaque)
To set the background of button as transparent do:
android:background="@android:color/transparent"
You can set a background for the button,then achieve the transparency by adjusting the alpha attribute of the button,
android:alpha="0.7"
Makes the opacity 70 percent.
You can set transparency with color. In Android color is broken into 4 8-bit (0-255) segments, with the first 8-bit (0-255) controlling the alpha. For example with the basic color code for Light Gray: D3D3D3. If I want light grey transparent, add 0 and to light grey and get 0D3d3d3 for 100% transparent, or 227(E3 in hex) and get E3D3D3D3 for 50% or 255(FF in Hex) and get FFD3D3D3 for 0%
Use this code in your background color
android:background="?android:attr/selectableItemBackground"
Just Use '@null'
to background of button makes transparency in button
android:background="@null"