Android 如何将对话框主题活动宽度设置为屏幕宽度?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2961833/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set a dialog themed activity width to screen width?
提问by Pentium10
I am followin the method described hereto create an EditText input activity. But the view doesn't fill the width of the screen. How can I tell to fit the screen width?
我按照此处描述的方法创建 EditText 输入活动。但是视图没有填满屏幕的宽度。我怎么知道适合屏幕宽度?
alt text http://img405.imageshack.us/img405/5057/activitythemed.png
替代文字 http://img405.imageshack.us/img405/5057/activitythemed.png
<activity android:name="TextEntryActivity"
android:label="My Activity"
android:theme="@android:style/Theme.Dialog"/>
-
——
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="vertical"
android:gravity="right"
android:layout_height="wrap_content">
<EditText
android:text="@+id/txtValue"
android:id="@+id/txtValue"
android:layout_width="fill_parent"
android:layout_height="wrap_content"></EditText>
<Button
android:text="Done"
android:id="@+id/btnDone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></Button>
</LinearLayout>
回答by Erich Douglass
Set android:minWidth
and/or android:minHeight
in your LinearLayout.
设置android:minWidth
和/或android:minHeight
在您的 LinearLayout 中。
回答by cdmckay
Another option is to use AlertDialog instead Dialog.
另一种选择是使用 AlertDialog 代替 Dialog。
回答by CaseyB
The short answer is that you can't. A dialog is only meant to wrap it's content. If you want the content to fill the screen you should be using an activity
简短的回答是你不能。对话框仅用于包装其内容。如果您希望内容填满屏幕,您应该使用活动