Android Addicted Apps Creator

September 11, 2012

Make Activity using Theme.Dialog fill the entire screen

Filed under: Tips — alinberce @ 07:55
Tags: , , ,

   Admitted, you hate using AlertDialog for complex layouts that contain many controls. I hate it, it makes me feel so limited. Of course it has its own advantages, let’s not be mean, but sometimes a new Activity unleashes the power within.

So, how do we make an Activity look like a dialog ? Simple, just add in manifest:

 <activity
            android:name=".MyDialogActivity"
             android:theme="@android:style/Theme.Dialog" />

    But the problem is, even if we set our layout properties, to fill_screen, the activity will wrap around the content and its size will vary of the info. I thought, if the xml setting is ignored, maybe setting it in code might work… and surprise, it does work. All you have to do is:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.my_dialog_layout);

    //after setContentView, set the Layout parameters to fill parent, this makes our activity to go full screen
    getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
}