Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

builder.setInverseBackgroundForced(true) does not work

I have in my code setInverseBackgroundForced set to true, but it doesn't appear to work. The code produces white text on a dark background.

Here is my builder code:

public class test {
    private void createMyLocationDisabledAlert() {
          AlertDialog.Builder builder = new AlertDialog.Builder(this);
          builder.setTitle("Title")
            .setInverseBackgroundForced(true)
            .setMessage(
                      "my message")
                      .setCancelable(false)
                      .setPositiveButton("Options",
                              new DialogInterface.OnClickListener() {
                          public void onClick(DialogInterface dialog, int id) {
                              showOptions();
                          }
                      });
          builder.setNegativeButton("Cancel",
                    new DialogInterface.OnClickListener() {
                 public void onClick(DialogInterface dialog, int id) {
                     dialog.cancel();
                 }
            });
          AlertDialog alert = builder.create();
          alert.show();
     }
}

What could I be doing wrong? I have tried the method call in different positions of the code block but to no resolve.

like image 552
qubz Avatar asked Nov 05 '22 05:11

qubz


1 Answers

setInverseBackgroundForced (boolean useInverseBackground) is deprecated in Android API level 23 (Android 6.0 Marshmallow).

This flag is only used for pre-Material themes. Instead, specify the window background using on the alert dialog theme.

Code is like this!

AlertDialog dialog = new AlertDialog.Builder(BaseActivity.this, R.style.Dark2).create();
dialog.getWindow().setBackgroundDrawableResource(android.R.color.background_dark);
like image 96
Htin Linn Zaw Avatar answered Nov 12 '22 19:11

Htin Linn Zaw