Android: How to make a modal custom view?

12,138

Solution 1

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); 

Solution 2

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

Share:
12,138
futlib
Author by

futlib

Updated on June 04, 2022

Comments

  • futlib
    futlib over 1 year

    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?