3

I've been working on an app and I've reaching the point where it requires me to display a menu window in the middle of the screen.

I've been using an AlertDialog object filled with a custom View but now it was required of me to "surround" the window with a semi-transparent white glow as opposed to the default grayish one. I did a similar with the fade-in color of some navigation drawers I have on my app but in that case I had a specific method to quickly help me solve that problem. So far I haven't found anything that helps me solve this one.

I tried creating a default style with a new "windowBackground" value but I encountered 3 problems from the get-go:

  • I'm no longer able to shut the AlertDialog down by clicking outside the layout (I'm guessing because by changing the color that way everything is now the layout)
  • The menu window is now surrounded by a black outline that wasn't there before
  • By using the filtering search inside the layout, which manipulates the members of a list, the window collapses on itself

Is there any way to accomplish what I want more or less directly?

rtnf
  • 31
  • 3

1 Answers1

2

I'm not really sure about it, but you can use this in your styles.xml

<style name="MyDialogTheme" parent="android:Theme.AppCompat.Light.Dialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@color/your_light_color</item>
<item name="android:backgroundDimEnabled">false</item>

And if you want to dismiss the dialog when clicking outside, use this:

dialog.setCanceledOnTouchOutside(true);

or

<item name="windowCloseOnTouchOutside">true</item>

in your styles.xml

javmarina
  • 493
  • 6
  • 17
  • Hey jav, thanks for replying. Even though your code was similar I had already tried, I gave it a go and I managed to get rid of the ugly black outline surrounding my main View. However I still can't dismiss the view by clicking outside of it, hence I maintain my theory that defining a window background makes the view occupy the whole screen. – rtnf Jul 07 '15 at 12:29
  • It's really strange. I don't know how to solve your issue. See [here](http://stackoverflow.com/questions/8384067/how-to-dismiss-the-dialog-with-click-on-outside-of-the-dialog) and try if it works. Also see [this](http://stackoverflow.com/questions/7214365/tap-outside-android-dialog-to-dismiss-it), [this](http://stackoverflow.com/questions/12102777/prevent-android-activity-dialog-from-closing-on-outside-touch) and [this](http://stackoverflow.com/questions/9516287/android-click-event-outside-a-dialog) – javmarina Jul 07 '15 at 14:00
  • Thanks for the recommendations. If any them end up solving my issue, I will indicate so here. – rtnf Jul 07 '15 at 14:37