I’m using an activity with android:theme=”@android:style/Theme.Dialog” to make it act as a dialog. What lies closest to the native behavior of dialogs: Should a dialog fill the screen (in width) or not? And should it grow dynamically if, for instance, a text box is filled up by typing?
My hunch is that the dialog should not fill the screen. I have tried to get this behavior, but whatever I do, on Android 2.2, the dialog width seems to fill the parent.
My layout xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical">
<TextView android:id="@+id/text" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:autoText="true"
android:text="@string/item_delete_dialog_label"
android:padding="5dip" />
<LinearLayout android:layout_height="wrap_content"
android:orientation="horizontal"
style="@android:style/ButtonBar" android:layout_width="fill_parent">
<Button android:id="@+id/yes" android:layout_height="wrap_content"
android:text="@string/button_yes"
android:layout_width="wrap_content"
android:layout_weight="1"/>
<Button android:id="@+id/no" android:layout_height="wrap_content"
android:text="@string/button_no"
android:layout_width="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
I’ve found many questions regarding making a dialog fill the screen in width, but none about making it wrap in width. How can I get this?
The ButtonBar style makes the dialog much wider than it would be using standard buttons. Changing the LinearLayout width to wrap_content won’t affect the width of the dialog as it’s merely filling the main LinearLayout container which is set to wrap_content – changing the button style will most definitely make a difference.