4

I've got an activity that occupies a portion of the screen (it has a style of style/android:Theme.Holo.Dialog.NoActionBar) and thus the other activity in the stack is visible beneath it.

When a button on the activity is clicked it displays a system dialog and the activity should disappear from view but the activity must still be present as its passed as a callback to the system dialog.

I tried setting the root view's (a RelativeLayout) visibility to INVISIBLE but that just turns the activity black and is visible beneath the system dialog. Setting the view's alpha to 0.0 also has the same effect.

Setting the view's visibility to GONE has the desired effect but there is a weird sort of animation type thing where the activity goes black and shrinks down on size to a tiny view just before the system dialog appears. This happens quite quickly but looks weird. Its something the OS must be doing as I'm certainly not doing anything to create this effect.

Is there another way I hide the activity that gets the desired result and doesn't a weird side effect artifact animation?

Gruntcakes
  • 37,738
  • 44
  • 184
  • 378

1 Answers1

6

First, follow these steps to make your activity window translucent: How do I create a transparent Activity on Android?

Then you could have a FrameLayout wrapping your whole activity layout(with transparent background) and as you show your Dialog set the views that are being wrapped by the FrameLayout as View.INVISIBLE .

This seems to work fine for your solution. Let me know.

To specify your theme use it as the parent of your new theme, like this:

<resources>
  <style name="Theme.YourCustomTransparentTheme" parent="android:Theme.Holo.Dialog.NoActionBar">
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:backgroundDimEnabled">false</item>
  </style>
</resources>

this way all your other properties will be maintained and you will add the transparent capability.

Community
  • 1
  • 1
luis.mazoni
  • 1,084
  • 8
  • 13
  • It already has the theme: Theme.Holo.Dialog.NoActionBar. How is it possible to specify it should have a Holo Dialog theme and a transparent theme? – Gruntcakes Oct 21 '15 at 17:22
  • Thanks, I'll give it try later (don't have the time at the moment), and accept the answer if it works. – Gruntcakes Oct 21 '15 at 21:32
  • That gets rid of the activity doing the strange shrinking thing. However the reason I am using Theme.Holo.Dialog is that with this theme the OS automatically dims the background. But when using the custom theme this dimming no longer occurs. – Gruntcakes Oct 22 '15 at 15:56
  • try changing the property android:backgroundDimEnabled to true... it should still work – luis.mazoni Oct 22 '15 at 16:02
  • Doh, I didn't spot that. Didn't have my morning coffee yet. Thanks for your answer and help. – Gruntcakes Oct 22 '15 at 16:23