Android 6.0 Dialog text doesn't appear

Veka picture Veka · Oct 20, 2015 · Viewed 22.7k times · Source

I updated my phone to Android 6.0 and I have these 2 problems with dialogs:

1)The title is shown but the messages isn't for alert dialog(SOLVED):

        new AlertDialog.Builder(context).setTitle("Title").setMessage("Message");

2)Also custom dialog fragment's title is not shown(NOT SOLVED):

        getDialog().setTitle("Title");

There was not such a problem in lollipop or in older versions, the problem appeared only after updating my phone to marshmallow.

How to solve the problem?

Answer

Oleksandr picture Oleksandr · Oct 21, 2015

Use constructor with theme for Lollipop and newer android versions:

Dark theme

    AlertDialog.Builder builder;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder = new AlertDialog.Builder(context, android.R.style.Theme_Material_Dialog_Alert);
    } else {
        builder = new AlertDialog.Builder(context);
    }

And for Light theme

    AlertDialog.Builder builder;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder = new AlertDialog.Builder(context, android.R.style.Theme_Material_Light_Dialog_Alert);
    } else {
        builder = new AlertDialog.Builder(context);
    }