Home > Software design >  MainActivity: change Dialog text color
MainActivity: change Dialog text color

Time:11-23

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()
    }

CodePudding user response:

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.

CodePudding user response:

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>"))

CodePudding user response:

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);
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

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()

  • Related