AlertDialog - 自定义视图和标题/按钮差距 [英] AlertDialog - gap between custom view and title/buttons
问题描述
我用一个AlertDialog自定义视图。在仿真器中,有一些空间上方和customeView下方。如果我设置了AlertDialog一个标题和按钮,我可以看到标题面板/按键面板和customView之间的差距。如何删除的差距?
I use a custom view for an AlertDialog. In the emulator, there is some space above and below the customeView. If I set a title and buttons for the AlertDialog, I can see the gap between the title panel/button panel and the customView. How can I remove the gap?
我的code打开AlertDialog:
My code to open the AlertDialog:
btnShowDialog.Click += (object sender, EventArgs e) =>
{
var customView = LayoutInflater.Inflate(Resource.Layout.myDialog, null);
var builder = new AlertDialog.Builder(this);
builder.SetTitle("Title");
builder.SetView(customView);
builder.Create().Show();
};
该customView布局:
The customView layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF">
<TextView
android:id="@+id/DialogText"
android:text="This is my custom view. Blur Blur Blur"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
<EditText
android:id="@+id/EnterPhone"
android:inputType="phone"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:hint="enter your number" />
</LinearLayout>
我已经测试AlertDialog中Android的4.0.3和4.1.2模拟器,并得到了同样的问题。
I have tested the AlertDialog in android 4.0.3 and 4.1.2 emulator and get the same issue.
感谢您的帮助!
推荐答案
而不是使用 AlertDialog
尝试使用对话框
而不是像这样:
Instead of using AlertDialog
try using Dialog
instead like so:
var dialog = new Dialog(this);
dialog.SetTitle("Hey there");
dialog.SetContentView(Resource.Layout.myDialog);
dialog.Show();
这让我在底部无缝隙的对话框。
This gives me the a dialog with no gap in the bottom.
您也可以离开标题出来和自定义视图填满整个对话框
。
You could also leave the title out and fill the entire Dialog
with your custom view.
var dialog = new Dialog(this);
dialog.RequestWindowFeature((int)WindowFeatures.NoTitle);
dialog.SetContentView(Resource.Layout.myDialog);
dialog.Show();
和使用此布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#000000">
<TextView
android:text="Hey there"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
style="@android:style/TextAppearance.DialogWindowTitle" />
</LinearLayout>
<TextView
android:id="@+id/DialogText"
android:text="This is my custom view. Blur Blur Blur"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
<EditText
android:id="@+id/EnterPhone"
android:inputType="phone"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:hint="enter your number" />
</LinearLayout>
这篇关于AlertDialog - 自定义视图和标题/按钮差距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!