Activity as Dialog Just On Larger Screen

924 Views Asked by At

I'm developing an Android app that needs to support 2.3+. I'm using HoloEverywhere as a layout library. My app runs perfectly on smartphones and tablets, but for now I'm using the same layout for all devices, so, in tablets there is a lot of blank space in a lot of layouts. So, I thinking if is possible to show this layout as a popup (AlertDialog) just on large screens.

I searched the internet for a response but every response I look isn't applying to my case. I don't want to change my layouts files (and, of course, I don't want to create new layout files).

Can anyone give a direction to solve my problem, or the unique way is to create new layouts for large screens?

3

There are 3 best solutions below

2
userM1433372 On BEST ANSWER

You can use your own layout file as the content view of a dialog. With a custom view you can create other/bigger dialogs for your tablets. It is also possible to create a dialog from an activity. See http://developer.android.com/guide/topics/ui/dialogs.html#ActivityAsDialog or http://developer.android.com/guide/topics/ui/dialogs.html#FullscreenDialog

0
Matob On

You can change the theme of activity to dialog in Manifest file. See:

<activity  
    android:name="Activity"  
    android:label="Home"  
    android:theme="@android:style/Theme.Holo.Dialog">  
</activity>
1
rupesh jain On

You can use this code to change the height and width of my activity in onCreate()..It provides better flexibility than specifying dialog theme

   Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width = size.x;
    int height = size.y;
    requestWindowFeature(Window.FEATURE_ACTION_BAR);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND,
            WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    android.view.WindowManager.LayoutParams params =
            getWindow().getAttributes();
    params.type = WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG;
    params.height = LayoutParams.WRAP_CONTENT;
    params.width = (int) (width / 1.2); // fixed width
    params.alpha = 1.0f;
    params.dimAmount = 0.5f;
    getWindow().setAttributes((android.view.WindowManager.LayoutParams)
            params);