Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android 6.0 Dialog text doesn't appear

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?

like image 764
Veka Avatar asked Oct 20 '15 05:10

Veka


People also ask

What is dialogue box in android?

A dialog is a small window that prompts the user to make a decision or enter additional information. A dialog does not fill the screen and is normally used for modal events that require users to take an action before they can proceed. Dialog Design.


1 Answers

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);     } 
like image 91
Oleksandr Avatar answered Oct 03 '22 17:10

Oleksandr