Android: How To Set Alertdialog To Material Design When Launched From An Activity With A Translucent Theme?
I am developing an app which triggers the following steps. Uses AlarmManager to trigger a BroadcastRecevier 5 seconds after launch. The BroadcastReceiver then sets off an Activity
Solution 1:
Change this line
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
to this:
AlertDialog alertDialog = new AlertDialog.Builder(this, R.style.Theme_MaterialComponents_Light_Dialog_Alert).create();
By passing a 2nd argument you allow the theme to be specified. If it's a root theme (a.k.a not derived from application themes) it will directly use its references.
Solution 2:
If you want to modify the alert dialog as per your wish. You can also use
builder.setView(inflatedView)
This will help you to make your own custom alert dialog where you can design the alert dialog as per your design and add as many buttons as required. Code will look like below. But you need to inflate your view before you pass it.
AlertDialogalertDialog=newAlertDialog.Builder(this).setView(inflatedView).create()
And for setting the background of the dialog you can use this.
alertDialog.window.setBackgroundDrawableResource(R.layout.background)
Post a Comment for "Android: How To Set Alertdialog To Material Design When Launched From An Activity With A Translucent Theme?"