Milo Milo - 21 days ago 7
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.

Thanks

Answer

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

 android:theme="@android:style/Theme.Dialog"

or

android:theme="@android:style/Theme.Holo.Dialog"

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

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

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:

if (Configuration.SCREENLAYOUT_SIZE_XLARGE)
{
//setTheme(yourDialogTheme);
}

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>
    </style>

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
        activity.requestWindowFeature(Window.FEATURE_ACTION_BAR);
        activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND,
                WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        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); 
    }