如何更改alertdialog上的正按钮的颜色?

时间:2017-12-19 20:30:25

标签: android kotlin

我想改变正面按钮的颜色。我怎么能这样做?

AlerDialog:

fun onSomeClicked(view: View) {
    val dialog: AlertDialog.Builder = AlertDialog.Builder(view.context)
    dialog.setTitle("SomeText")
            .setMessage("SomeMessage")
            .setPositiveButton(view.context.getString(R.string.ok_dialog)) { p0, p1 ->
                onCheckPassword(view)
            }
            .setNegativeButton(context.getString(R.string.cancel_dialog)) { p0, p1 ->

            }
            .create()
            .show()

}

谢谢! (我的问题是在科特林,在科特林做。)

1 个答案:

答案 0 :(得分:3)

一些小改动会做你想要的事情 -

val builder: AlertDialog.Builder = AlertDialog.Builder(this)
val dialog: AlertDialog = builder.setTitle("SomeText")
           .setMessage("SomeMessage")
           .setPositiveButton("OK") {
               dialog, which -> dialog.dismiss()
           }
           .setNegativeButton("Cancel") { dialog, which -> dialog.dismiss()

           }
           .create()
dialog.show()

dialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(Color.BLUE)

dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(Color.DKGRAY)

希望它会有所帮助。