I would like to make my own dialog, completely drawn myself, as a custom view. Can I d开发者_开发技巧isplay 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?
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);
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.
http://developer.android.com/guide/topics/ui/themes.html
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.
精彩评论