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 SQL Server下载
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥15 python爬取bilibili校园招聘网站
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件
  • ¥15 不同系统编译兼容问题
  • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?
  • ¥30 数字电源对DSP芯片的具体要求