Strange behavior when applying a theme to a dialogue under api 21

I am using the theme "Theme.AppCompat.Light.NoActionBar" in my application. I want some of my dialogs to apply the dark AppCompat theme.

So, I created a style for dialogue

  <style name="MyDialogStyle" parent="Theme.AppCompat.Dialog"> </style> 

(same problem when the parent is "Theme.AppCompat.Dialog.Alert") the same in the xml file without version limitation and the same style in the xml file with api version 21 constrain. to call the dialog box I used this function:

  public void showSimplestDialog(View view) { AlertDialog.Builder builder = new AlertDialog.Builder(this,R.style.MyDialogStyle); AlertDialog alertDialog = builder.setTitle("title") .setMessage("message ") .create(); alertDialog.show(); } 

The result in api 21+ looks great

enter image description here

but in api 17 I have a duplicate background that I can’t get rid of (even when I try to apply a custom view to the dialog with builder.setView (MyView)

enter image description here

+2
android styles dialog themes
source share
1 answer

Make sure you have to import android.support.v7.app.AlertDialog this thing.

Then create this method

 AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.DialogStyle); builder.setTitle("Title"); builder.setMessage("Abc ..."); builder.setPositiveButton("OK", null); builder.setNegativeButton("Cancel", null); builder.show(); 

and create a style in styles.xml

 <style name="DialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert"> <item name="colorAccent">#FFCC00</item> <item name="android:textColorPrimary">#FFFFFF</item> <item name="android:background">#5fa3d0</item> </style> 
+1
source share

All Articles