【问题标题】:Dialog with AlertDialog style带有 AlertDialog 样式的对话框
【发布时间】:2012-10-30 14:16:42
【问题描述】:

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

  1. 宽度太小
  2. 我无法删除标题空间

所以,我需要

但是得到:

调用代码:

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>

如何解决这个问题?请帮忙。

【问题讨论】:

    标签: android dialog android-alertdialog


    【解决方案1】:

    你试过了吗:

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

    和

    dialog.getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); //for the width
    

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

    ?

    【讨论】:

    • 感谢您的回答!标题现在不显示,没关系。但宽度没有改变。请问这个问题有没有别的办法解决?
    • 如果我记得,dialog.getWindow().setLayout 必须在 setContentView 之后完成
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-14
    • 2016-12-28
    相关资源
    最近更新 更多