Android: make everything around Dialog darker than default

iseeall picture iseeall · Jun 29, 2011 · Viewed 13.6k times · Source

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!

Answer

Mark Allison picture Mark Allison · Jun 29, 2011

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