【问题标题】:Dialog with own layout in androidandroid中具有自己布局的对话框
【发布时间】:2012-08-22 17:33:00
【问题描述】:

我有一个屏幕,里面有一些按钮。我想知道我该怎么做这样的事情:当我点击按钮应用程序时,我会显示我的界面对话框,我可以在两个编辑框中编写文本,在这个对话框中我想要一个按钮。这可以用我自己的界面进行对话吗?

【问题讨论】:

    标签: android android-layout


    【解决方案1】:

    是的,您实际上可以扩展布局并在警报对话框中生成它

           LayoutInflater factory = LayoutInflater.from(this);
            final View textEntryView = factory.inflate(R.layout.alert_dialog_text_entry, null);
            return new AlertDialog.Builder(AlertDialogSamples.this)
                .setIcon(R.drawable.alert_dialog_icon)
                .setTitle(R.string.alert_dialog_text_entry)
                .setView(textEntryView)
                .setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
    
                        /* User clicked OK so do some stuff */
                    }
                })
                .setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
    
                        /* User clicked cancel so do some stuff */
                    }
                })
                .create();
    

    这是来自 api 示例中提供的示例代码

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多