【问题标题】:Change Custom Dialog 'header' to AlertDialog 'header'将自定义对话框的“标题”更改为 AlertDialog 的“标题”
【发布时间】:2011-01-19 09:15:50
【问题描述】:

我制作了一个自定义对话框,我希望标题具有像 AlertDialog 这样的背景。

说得好:

显示“自定义对话框”的地方

需要有这样的“标题”:

我不想只是将图像左侧添加到文本中,而是真正实现显示的完整 UI 样式。

这可能吗?

这是我用于自定义对话框的代码:Adding Image to Custom AlertDialog

【问题讨论】:

    标签: android layout dialog android-alertdialog


    【解决方案1】:

    Galip 这是对我有用的代码

    Dialog dialog = new Dialog(context);
    
    dialog.setContentView(R.layout.dialoglayout);
    
    dialog.setTitle("Pick A Colour");
    

    在我的对话框布局中,我有根元素 RadioGroup

    希望对你有帮助。

    【讨论】:

      【解决方案2】:

      那么为什么不使用经典的AlertDialog.Builder 呢?

      AlertDialog.Builder builder = new AlertDialog.Builder( activity );
      builder.setTitle( title );
      builder.setView( /* Your custom view here */ );
      
      // optional
      builder.setPositiveButton( R.string.button_ok, listener );
      builder.setNegativeButton( R.string.button_cancel, listener );
      
      AlertDialog alert = builder.create();
      alert.show();
      

      然后您将拥有系统对话框的外观和感觉。

      【讨论】:

      • 已经尝试过了,我只是不知道如何构建看起来与普通的类似列表视图的内容完全一样的 XML 视图 only 与右侧对齐的另一个文本视图一边。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-16
      相关资源
      最近更新 更多