I would like to make my own dialog, completely drawn myself, as a custom view. Can I display it in such a way that it displays above all other views and that all touch events, even those outside the dialog's area, are redirected to the dialog?
3 Answers
I find that using a transparent activity and startActivityForResult() gives me a total freedom how I want my "dialog" to look and behave. So I suggest you check it out: How do I create a transparent Activity on Android?
With full screen and a darker background of your choice:
<style name="Theme.Transparent" parent="@android:style/Theme.Translucent.NoTitleBar.Fullscreen">
<item name="android:windowBackground">@color/transparentActivityBackground</item>
</style>
Then in strings.xml:
<color name="transparentActivityBackground">#55000000</color>
If you want to blur the screen of the previous activity then use this line before setContentView:
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
-
Sounds like the most reasonable approach in my situation, thanks! I guess I'll be fine if I just use the built-in Theme.Transluent. – futlib Mar 01 '11 at 14:54
-
Also it is important to learn how to make a 9 patch png image which perfectly streaches to make a background for any view, even the text one. Look in C:\android-sdk-windows\tools\ for draw9patch.bat – Lumis Mar 01 '11 at 15:24
-
FLAG_BLUR_BEHIND is deprecated – bhaskarc Jan 10 '14 at 15:41
This should be possible by setting the height/width of the root element to anything but fill_parent
.
You could also achieve this by creating a custom theme that inherits from the built in android dialog theme.

- 903
- 1
- 9
- 26
-
You mean the dialog's root element? If I don't set it to fill_parent, the user can still interact with the elements beneath, right? – futlib Feb 20 '11 at 16:32
-
Upvoted for the suggestion to create a custom dialog theme and use a customized Dialog. You will have a much smoother time doing it that way than trying to put a special view into the hierarchy of an existing window that behaves like a dialog. Dialogs are already there for you to use. :-) The main change you'll want to make in such a custom theme will probably be the windowBackground. – adamp Feb 20 '11 at 17:22
-
Yeah I think your right about the background views, I didn't think about that. But as adamp pointed out, using the built in dialogs should help make it easier. – AverageMarcus Feb 20 '11 at 17:49
Here's my workaround.
First, obtain the decor view's content child view, which is a FrameLayout
, using Window#getDecorView().findViewById(android.R.id.content)
.
Then, add your custom view to this FrameLayout
and it will be at the top of other views.

- 951
- 10
- 16