Android Dialog Semi-Transparent

好久不见. 提交于 2019-12-06 05:17:39

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.

David

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/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!