Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/183.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在垂直中心显示自定义对话框_Android_Dialog_Customdialog - Fatal编程技术网

Android 如何在垂直中心显示自定义对话框

Android 如何在垂直中心显示自定义对话框,android,dialog,customdialog,Android,Dialog,Customdialog,查看屏幕截图对话框未显示垂直居中和意外边距 我试过很多例子,但没有人能解决这个问题。 请参考屏幕截图,以便您很容易理解我的问题是什么。 “如您所见-对话框以意外边距显示” 我也试过这个 Window-Window=dialog.getWindow(); window.setLayout(AppBarLayout.LayoutParams.WRAP_内容, AppBarLayout.LayoutParams.WRAP_内容); 设置重力(重心) java代码是- final Dialog dia

查看屏幕截图对话框未显示垂直居中和意外边距

我试过很多例子,但没有人能解决这个问题。 请参考屏幕截图,以便您很容易理解我的问题是什么。 “如您所见-对话框以意外边距显示”

我也试过这个

Window-Window=dialog.getWindow(); window.setLayout(AppBarLayout.LayoutParams.WRAP_内容, AppBarLayout.LayoutParams.WRAP_内容); 设置重力(重心)

java代码是-

final Dialog dialog = new Dialog(MainActivity.this);
            dialog.setContentView(R.layout.dialogforgot_password);
            final EditText et_emailforgot = (EditText)dialog.findViewById(R.id.et_EnterMail);
            final Button bt_SubmitForgotPass = (Button)dialog.findViewById(R.id.bt_SubmitForgotButton);
            final TextView ForgotHeading = (TextView)dialog.findViewById(R.id.tv_forgotpasswordHeading);
            final TextView PleaseEnterurMail = (TextView)dialog.findViewById(R.id.tv_Enteruremail);
            et_emailforgot.setTypeface(Lato_Regular);
            PleaseEnterurMail.setTypeface(Lato_Regular);
            ForgotHeading.setTypeface(Lato_Bold);
            bt_SubmitForgotPass.setTypeface(Lato_Bold);
            dialog.show();
我的XML文件如下所示:

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/rounded_windowcorner"
>
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:background="@drawable/rounded_headingcorner"
    android:layout_alignParentTop="true"
    android:id="@+id/RLForgot">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Forgot Password"
        android:textColor="#ffffff"
        android:textSize="16dp"
        android:id="@+id/tv_forgotpasswordHeading"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />
</RelativeLayout>
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Please Enter Your Registered Email id"
        android:textColor="#000000"
        android:textSize="17dp"
        android:layout_marginRight="22dp"
        android:layout_marginLeft="22dp"
        android:id="@+id/tv_Enteruremail"
        android:layout_centerHorizontal="true"
        android:layout_below="@+id/RLForgot"
        android:layout_marginTop="20dp"
        android:textAlignment="center"
        />
    <EditText
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:textAlignment="center"
        android:id="@+id/et_EnterMail"
        android:hint="Enter Your Email Id Here"
        android:singleLine="true"
        android:background="@drawable/custom_spinner_background"
        android:layout_centerHorizontal="true"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="40dp"
        android:layout_below="@+id/tv_Enteruremail"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:text="Submit"
        android:background="@drawable/signin_btn"
        android:textColor="@color/signinlogcolor"
        style="?android:attr/borderlessButtonStyle"
        android:id="@+id/bt_SubmitForgotButton"
        android:layout_marginTop="30dp"
        android:layout_marginBottom="10dp"
        android:layout_below="@+id/et_EnterMail"
        android:layout_centerHorizontal="true" />
        </RelativeLayout>

我的问题是什么。“如您所见-对话框以意外边距显示”

它被称为
对话框
标题使用
对话框.requestWindowFeature(Window.FEATURE\u NO\u标题);
对话框中删除标题
如下
code

试试这个

final Dialog dialog = new Dialog(MainActivity.this);    
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialogforgot_password);
对话框中没有任何意外的空白

您的对话框已垂直对齐中心。因为你有标题栏,它似乎关闭了


对话框初始化后

改用AppCompatDialog。@Kishor请检查我的答案。谢谢,正在工作Fine@Kishor很高兴帮助你
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);