Milo Milo - 2 months ago 15
Android Question

Display Activity as overlay window on tablets

How do you present an Activity as an overlay window on tablets? An example of this is the new Google+ app as seen here:

enter image description here

Importantly I want the ActionBar to be part of the window and for the Activity beneath to be dimmed as seen in the screenshot.



You can just use dialog theme. To do this, just write in Manifest:




or just by creating your own theme in styles.xml:

<style name="MyDialogTheme" parent="Theme.Holo.Dialog">

You can set such theme for xlarge or large screen by creating styles.xml in values-xlarge or values-large folders.

If you want to set this theme only for tablets, then you can change theme dynamically by checking the screen size like this:


Please check this answer if you want dialog with action bar. You can do this by creating your custom dialog.

Dialog themed activity with action bar

Custom dialog

EDIT: An answer from google group post. Try this in your xml with styles:

<style name="PopupTheme" parent="android:Theme.Holo.Light.Dialog">
        <item name="android:windowIsFloating">false</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowSoftInputMode">stateAlwaysHidden</item>
        <item name="android:windowActionModeOverlay">true</item>
        <item name="android:windowIsTranslucent">true</item>

In Java code

public static void showAsPopup(Activity activity) {
        //To show activity as dialog and dim the background, you need to declare android:theme="@style/PopupTheme" on for the chosen activity on the manifest
        LayoutParams params = activity.getWindow().getAttributes(); 
        params.height = LayoutParams.FILL_PARENT;
        params.width = 850; //fixed width
        params.alpha = 1.0f;
        params.dimAmount = 0.5f;
        activity.getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);