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

问题描述 投票:0回答:2

我正在与最愚蠢的事情挣扎。我想删除上面的空间。我在原生Android中找到了一个代码,但在Xamarin Android中无法找到相同的代码,

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

Code for Native Android在Activity中,我们使用Dialog Box“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>
android xamarin xamarin.android
2个回答
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();

0
投票

在MainActivity类中

@Override
    protected void onCreate(Bundle savedInstanceState) {
        // some code here
        ActionBar actionBar = getActionBar();
        actionBar.setDisplayShowTitleEnabled(false);
    }
© www.soinside.com 2019 - 2024. All rights reserved.