myc_100 2013-04-01 06:31 采纳率: 10%
浏览 3172
已采纳

Button 从对话框布局中消失

为什么 button 不能在对话框窗口中显示出来?

  Dialog d = new Dialog(AddContact.this);

    LayoutInflater li = (LayoutInflater) getSystemService(Service.LAYOUT_INFLATER_SERVICE);
    ViewGroup contentView = (ViewGroup) li.inflate(R.layout.dialog,null);

    d.setContentView(contentView);
    d.setTitle("Please correct these errors:");

    TextView error = (TextView) contentView.findViewById(R.id.textView1);
    Button closer = (Button) contentView.findViewById(R.id.button1);

    closer.setText("Close");
    error.setText(errorMessage);
    d.show();

dialog.xml layout 文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:orientation="vertical" android:padding="5dp">
       <TextView android:text="TextView" android:id="@+id/textView1"
        android:layout_height="fill_parent" android:layout_width="fill_parent" />
    <Button android:text="Button" android:id="@+id/button1"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:gravity="center" />
    </LinearLayout>
  • 写回答

3条回答 默认 最新

  • ssummeraw 2013-04-01 08:26
    关注

    使用下面的代码:
    只更换 dialog.xml layout 文件中的 Textview

    <TextView android:text="TextView" android:id="@+id/textView1"
            android:layout_height="wrap_content" android:layout_width="fill_parent" />
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记