我正在使用带有 android:theme="@android:style/Theme.Dialog"的 Activity 来使其充当对话框。什么最接近对话框的 native 行为:对话框是否应该填满屏幕(宽度)?并且它是否应该动态增长,例如,如果通过键入填充文本框?
我的预感是对话框不应填满屏幕。我试图获得这种行为,但无论我做什么,在 Android 2.2 上,对话框宽度似乎填满了父级。
我的布局 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>
我发现了很多关于让对话框在宽度上填满屏幕的问题,但没有一个关于让它在宽度上换行的问题。我怎样才能得到这个?
最佳答案
ButtonBar 样式使对话框比使用标准按钮宽得多。将 LinearLayout 宽度更改为 wrap_content 不会影响对话框的宽度,因为它只是填充设置为 wrap_content 的主 LinearLayout 容器 - 更改按钮样式肯定会有所不同。
关于Android:对话框的宽度应该是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4939001/