Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 597
Milo Avatar asked May 26 '13 11:05

Milo


2 Answers

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); 
    }
like image 127
Yuriy Yunikov Avatar answered Oct 06 '22 00:10

Yuriy Yunikov


You should use the Theme.Dialog in you Manifest.xml for the Activity

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

for future use you should use an CustomTheme in you values/values-11/values-14->styles.xml (EDIT)

EDIT:

         <activity 
             android:name="com.apps.ActivityP" 
             android:theme="@style/CustomTheme"/> 

in you values styles.xml folder

<style name="CustomTheme" parent="android:Theme.Black">

for example you values-11/14 styles.xml folder

<style name="CustomTheme" parent="android:Theme.Holo.Dialog">
like image 33
Oli Avatar answered Oct 06 '22 00:10

Oli