删除顶部的Xamarin Android警报对话框空白

时间:2019-03-28 12:43:11

标签: android xamarin xamarin.android

我正在为最愚蠢的事情而苦苦挣扎。我想删除上面的空格。我在本机Android中找到了一个代码,但在Xamarin Android中找不到相同的代码,

这是图像,显示空白区域:

Showing Space

本机Android的代码在Activity中,我们正在其中使用对话框“ dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);”

代码在下面

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:background="@android:color/white"
  android:layout_width="match_parent"
  android:layout_height="wrap_content">
<LinearLayout
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:padding="10dp"
    android:background="@android:color/white"
    android:orientation="vertical"
    android:minWidth="25px"
    android:minHeight="25px"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/linearLayout1" >
<TextView
    android:textColor="@android:color/black"
    android:text="Are you Sure ?"
    android:textSize="20dp"
    android:gravity="center"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/textView1" />
<TextView
    android:layout_marginTop="10dp"
    android:text="You are about to sign out.Do"
    android:gravity="center"
    android:textColor="@android:color/black"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/textView2" />
<TextView
    android:gravity="center"
    android:text="you want to continue ?"
    android:textColor="@android:color/black"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/textView3" />
<GridLayout
    android:layout_margin="2dp"
    android:layout_gravity="center"
    android:minWidth="25px"
    android:minHeight="25px"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/gridLayout1" >
<Button
    android:background="@drawable/noredbutton"
    android:layout_column="0"
    android:layout_columnWeight="0.5"
    android:gravity="center"
    android:layout_margin="10dp"
    android:text="No"
    android:textColor="@android:color/white"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/button1" />
<Button
    android:background="@drawable/yesgreenbutton"
    android:layout_columnWeight="0.5"
    android:gravity="center"
    android:layout_margin="10dp"
    android:layout_column="1"
    android:text="Yes"
    android:textColor="@android:color/white"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/button2" />
 </GridLayout>
 </LinearLayout>

</LinearLayout>

2 个答案:

答案 0 :(得分:1)

您可以直接使用Dialog

活动中:

 //Resource.Layout.dialog is your axml of dialog
 View view = LayoutInflater.From(this).Inflate(Resource.Layout.dialog,null);
 Button btn1 = view.FindViewById<Button>(Resource.Id.button1);
 Button btn2 = view.FindViewById<Button>(Resource.Id.button2);
 Dialog dialog = new Dialog(this);
 dialog.RequestWindowFeature((int) WindowFeatures.NoTitle);
 dialog.SetContentView(view);
 btn1.Click += delegate { Toast.MakeText(this, "no", ToastLength.Short).Show(); };
 btn2.Click += delegate {Toast.MakeText(this,"yes",ToastLength.Short).Show(); };
 dialog.Show();

答案 1 :(得分:0)

在MainActivity类内部

@Override
    protected void onCreate(Bundle savedInstanceState) {
        // some code here
        ActionBar actionBar = getActionBar();
        actionBar.setDisplayShowTitleEnabled(false);
    }