I am trying to make a semi-transparent Dialog so that you can see the game in the background before it starts.
I've looked at this article on how to make it transparent, but there's nothing really on semi-transparent or if it's possible.
What I want is kind of like the picture he provides, but what the solution gives is the background of the dialog being completely gone.
Thanks a lot!
Set the background color to #AARRGGBB where AA is the alpha channel. For example you could use #00000000 for the color or the short method: #ARGB so that would be #0000 Using the shorthand notation the values are each just used twice where #264C would be the same as #226644CC See also Android Color for more.
You can keep using the code provided at android dialog transparent.
Create at colors.xml the background color that you want, for example:
<color name="translucent_black">#80000000</color>
and set the dialog to have the translucent_black with:
mDialog.getWindow().setBackgroundDrawableResource(R.color.translucent_black);
Note: the alpha channel is represented by the first two digits passed on the color resource. In the example I'm setting the alpha to be "80". You can read more about android colors at Android Color.
If you want to use partial transparency, this would help you while setting your color codes.
2 hex characters can be appended to any hex color code. The first 2 characters in an 8-digit hex color code represents its opacity in Android.
The 2 hex characters can range from 00 to FF. For example-
- Normal opaque black hex- "#000000"
- Fully transparent black- "#00000000"
- Fully opaque black- "#FF000000"
- 50% transparent black- "#80000000"
This way you can change any color to any level of transparency.
Use this to find the Hex prefix from a percentage-
Divide the % by 100 and multiply by 255 to get the decimal value. Convert the decimal to hex here eg. for 50%, 50/100 * 255 = 128. Using the link we get hex value 80.
Source- http://zaman91.wordpress.com/2010/03/22/android-how-to-create-transparent-or-opeque-background/
来源:https://stackoverflow.com/questions/12256490/android-dialog-semi-transparent