Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: make everything around Dialog darker than default

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!

like image 760
iseeall Avatar asked Jun 29 '11 10:06

iseeall


3 Answers

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
like image 191
Mark Allison Avatar answered Nov 11 '22 16:11

Mark Allison


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); 
like image 38
Yasitha Waduge Avatar answered Nov 11 '22 17:11

Yasitha Waduge


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); 
like image 1
Vishal Raj Avatar answered Nov 11 '22 17:11

Vishal Raj