Builder.setInverseBackgroundForced (true) not working

I have setInverseBackgroundForced in my code set to true, but it does not work. The code creates white text on a dark background.

Here is my developer 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 can i do wrong? I tried calling the method in different positions of the code block, but without permission.

+4
source share
2 answers

A custom user dialog that extends DialogFragment and uses it to display AlertDialog.

Example:

 public class CustomAlertDialog extends DialogFragment { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { 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(); return alert; } } public class test { private void createMyLocationDisabledAlert() { new CustomAlertDialog().show(getSupportFragmentManager(), Constants.FragmentTagSearch); } } 

Note. I used the support library for compatibility, therefore using getSupportFragmentManager() .

0
source

I am also facing the same problem today. And, as of today, the Android document says that the setInverseBackgroundForced() API is deprecated and recommends that the developer specify the window background using the warning dialog box theme.

Note. An exception should ideally not stop a function from working.

However, I didnโ€™t want to investigate why it doesnโ€™t work today, and switched my attention to making everything an cleaner and more recommended way for Android documents. And this is something like the code below:

 private final int DIALOG_THEME_STYLE = android.support.v7.appcompat.R.style.Base_Theme_AppCompat_Dialog_MinWidth; AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this, DIALOG_THEME_STYLE); 

Hope this helps!

0
source

All Articles