【问题标题】:AlertDialog buttons positioningAlertDialog 按钮定位
【发布时间】:2021-03-31 23:58:29
【问题描述】:

我在 Kotlin 中有一个简单的对话框:

        AlertDialog.Builder(this)
                .setTitle("Title")
                .setMessage("Message")
                .setPositiveButton("Ok"){dialog, _ ->
                }
                .setNeutralButton("Wait") {dialog, _ ->
                }
                .setNegativeButton("Cancel") { dialog, _ ->                   
                }
                .show()

但是,按钮显示为:


等待取消确定


我的预期是:


取消等待确定


如果不创建自定义布局,这可能吗?

【问题讨论】:

    标签: android android-layout kotlin


    【解决方案1】:

    感谢您的提问。我已经尝试过了,我切换了按钮,最后得到了这个:

            AlertDialog.Builder(this)
            .setTitle("Title")
            .setMessage("Message")
            .setPositiveButton("Ok"){dialog, _ ->
            }
            .setNeutralButton("Cancel") {dialog, _ ->
            }
            .setNegativeButton("Wait") { dialog, _ ->
            }
            .show()
    

    输出这个AlertDialog:

    让我知道它是否有效。

    【讨论】:

    • 是的,这是一个简单的修复,但 positivenegative 除了名称之外没有其他区别?我试图避免这种情况,因为当我之后为每个按钮实现事件侦听器时,它会使我的代码看起来很糟糕
    猜你喜欢
    • 1970-01-01
    • 2011-08-14
    • 1970-01-01
    • 2011-04-10
    • 2011-11-23
    • 2011-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多