0

everyone. Please, how can I change the color of my dialog text? I have succeeded in changing the background color to black, so I want to change the text to white. Below is my code:

fun notificationofWinner(player: Int) {
        val alert = AlertDialog.Builder(this@MainActivity, R.style.MyDialogTheme)
        alert.setTitle("GAME OVER! Player $player wins!!!")
        alert.setPositiveButton("Ok") { dialog , Button -> }
        alert.show()
    }
AleBuo
  • 195
  • 1
  • 9

3 Answers3

0

In your style R.style.MyDialogTheme

Add your textColor or a whole textStyle.

This answer should get you started

AlertDialog styling - how to change style (color) of title, message, etc

My personal preference is to make a DialogFragment instead as you will get a lot more freedom out of using it than the basic AlertDialog.

avalerio
  • 2,072
  • 1
  • 12
  • 11
0

If you don't want to change in your style, you can do it with Html like... alert.setTitle(Html.fromHtml("<font color='#ffffff'>GAME OVER! Player $player wins!!</font>"))

Android
  • 82
  • 1
  • 8
0

If you want the full control over the appearance of a dialog box, you should consider making a custom dialog box like this.

Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.custom_dialog);

where custom_dialog is your custom dialog layout file. Customise as however you want.

Use dialog.show() whenever you want to show the dialog and to hide, use dialog.hide() or dialog.dismiss()