Android 具有AlertDialog样式的对话框

Android 具有AlertDialog样式的对话框,android,dialog,android-alertdialog,Android,Dialog,Android Alertdialog,在我的项目中,我需要使用自定义对话框而不是AlertDialog。但我对对话框样式有两个问题: 宽度太小 我无法删除标题空间 所以,我需要 但是你可以得到: 呼叫代码: Dialog dialog = new Dialog(this); dialog.setContentView(R.layout.write_message); dialog.show(); 布局XML: <?xml version="1.0" encoding="utf-8"?> <LinearLayo

在我的项目中,我需要使用自定义对话框而不是AlertDialog。但我对对话框样式有两个问题:

  • 宽度太小
  • 我无法删除标题空间
  • 所以,我需要

    但是你可以得到:

    呼叫代码:

    Dialog dialog = new Dialog(this);
    dialog.setContentView(R.layout.write_message);
    dialog.show();
    
    布局XML:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
    
    
        <EditText
            android:id="@+id/message"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="textMultiLine"
            android:minLines="3" >
    
            <requestFocus />
        </EditText>
    
    
        <Button
            android:id="@+id/send_message"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/send_message" />
    
    </LinearLayout>
    
    
    
    如何解决这个问题?请帮忙。

    您是否尝试过:

    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); //for the title space
    

    如果需要,可以在布局xml中添加填充


    谢谢您的回答!标题现在没有显示,没关系。但宽度没有改变。这个问题可能还有其他解决方法吗?如果我记得的话,dialog.getWindow().setLayout必须在setContentView之后完成
    dialog.getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); //for the width