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条)

报告相同问题?

悬赏问题

  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程