Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the color of an AlertDialog message?

Tags:

I have an AlertDialog and it's message is displayed, but the color of the text is white. It blends in with the background. I've tried changing the theme but it doesn't work. How do I change the color of the message?

The relevant code:

AlertDialog.Builder builder; builder = new AlertDialog.Builder(MainActivityGame.this);  builder.setTitle("Name"); builder.setMessage("Are you "); builder.setCancelable(false); builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {     @Override     public void onClick(DialogInterface dialogInterface, int i) {         //Submit default name, go home         boolean isInserted = myDb.insertData(defaultName, triesTaken, difficultyText);         if (isInserted) {             Toast.makeText(MainActivityGame.this, "Your name was submitted", Toast.LENGTH_SHORT).show();         } else {             Toast.makeText(MainActivityGame.this, "Error, your name wasn't submitted\n Have you entered a default name?\n Go to Settings/Default Name to set it up", Toast.LENGTH_SHORT).show();         }         Intent intent = new Intent(MainActivityGame.this, MainActivity.class);         startActivity(intent);     } }); builder.setNegativeButton("No", new DialogInterface.OnClickListener() {     @Override     public void onClick(DialogInterface dialogInterface, int i) {         userName.setVisibility(View.VISIBLE);         submitName.setVisibility(View.VISIBLE);         submitName.setEnabled(true);         dialogInterface.dismiss();     } }); builder.create(); builder.show(); 
like image 690
8bit an3 Avatar asked Jun 18 '17 19:06

8bit an3


People also ask

How do I change my AlertDialog color?

To change the background color of AlertDialog in Flutter, set the backgroundColor property of AlertDialog with the required color.

How do I change the background color on AlertDialog builder?

Use setInverseBackgroundForced(true) on the alert dialog builder to invert the background.

Is AlertDialog deprecated?

A simple dialog containing an DatePicker . This class was deprecated in API level 26.


1 Answers

you can give style to your alert dialog like this:

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.AlertDialogStyle); 

and the style is like always:

<style name="AlertDialogStyle" parent="Theme.AppCompat.Light.Dialog">     <item name="android:colorAccent">#f3f3f3</item>     <item name="android:textColor">#f3f3f3</item>     <item name="android:textColorPrimary">#f3f3f3</item> </style> 
like image 71
Meikiem Avatar answered Oct 08 '22 23:10

Meikiem