How do I change the color of the AlertDialog message?

I have AlertDialog

and this message is displayed but the text color is white. It blends into the background. I tried to change the theme, but it doesn't work. How do I change the color of a message?

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

      

+3


source to share


2 answers


you can specify a style for your alert dialog, for example:

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

      



and the style is always like:

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

      

+9


source


You can use this method like @KarimElGhandour mentioned or just create your own Layout

in the folder res\layout

and then apply it with alertDialog.setView(LayoutInflater.inflate(R.layout.yourlayout), yourRootView

.



0


source







All Articles