i have a custom dialog with following style:
<style name="webtogo_app_style" parent="@android:style/Theme.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
</style>
It shows a borderless dialog, and anything behind gets (slightly) darker. My designer wants that everything behind got ever more dark than Android's default, but not completely black.
Is there a setting for this at all?
The only workaround I can think of is to use a full-screen activity instead of a dialog and just fill up the whole screen with semitransparent color (e.g. #99000000) and then draw my dialog over it. Is there an easier way?
Thanks!
All you need to do is play around with the dimAmount
field in the WindowManager.LayoutParams
:
WindowManager.LayoutParams lp = myDialog.getWindow().getAttributes();
lp.dimAmount = 0.7f
If you are creating custom dialog with theme translucent, you have to add below line as well. and you can control dim amount using above answer's code.
myDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
For me it looks like below:
WindowManager.LayoutParams lp = myDialog.getWindow().getAttributes();
lp.dimAmount = 0.7f
myDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
WindowManager.LayoutParams lp=getWindow().getAttributes();
//set transparency of background
lp.dimAmount=0.6f; // dimAmount between 0.0f and 1.0f, 1.0f is completely dark
//lp.width = 200;
//lp.height = 300;
myDialog.getWindow().setAttributes(lp);
myDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With