I've created a Dialog using below code in android.
final CharSequence[] ss = {"1", "2", "3", "4"};
AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.MyAlertDialogStyle);
builder.setTitle("title");
builder.setItems(ss, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
builder.show();
This is MyAlertDialogStyle.xml.
<style name="MyAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">#color/red</item>
<item name="android:textColorPrimary">#color/black</item>
<item name="android:background">#color/background</item>
<item name="android:windowMinWidthMajor">#android:dimen/dialog_min_width_major</item>
<item name="android:windowMinWidthMinor">#android:dimen/dialog_min_width_minor</item>
</style>
There are no effects when pressing items in a dialog. What should I do to change background colors of dialog when pressed in xml file?
Additionally, is there any way to know the list of items that I can modify in xml file?(e.g. colorAccent, backgound, textColorPrimary ...)
You could try with MaterialDialogs library. It's easy to use and you could get the callbacks from buttons / radio / etc even if it's with a custom view.
(link : https://github.com/afollestad/material-dialogs/)
Try next code:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorAccent">#color/accent</item>
<item name="android:dialogTheme">#style/DialogStyle</item>
<item name="android:alertDialogTheme">#style/DialogStyle</item>
</style>
<style name="DialogStyle" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#color/accent</item>
<item name="android:windowTitleStyle">#style/DialogTitleStyle</item>
<item name="android:textColorAlertDialogListItem">#color/text_color</item>
<item name="android:textAppearanceButton">#style/DialogWindowTextButton</item>
<item name="android:windowBackground">#android:color/transparent</item>
</style>
<!--Colors and Styles-->
<color name="bar">#FF5722</color>
<color name="status_bar">#E64A19</color>
...
...
Related
I have set up my app as follows:
build.gradle
implementation 'com.google.android.material:material:1.1.0'
styles.xml
<style name="AlertDialogTheme" parent="ThemeOverlay.MaterialComponents.Dialog.Alert">
<item name="buttonBarNegativeButtonStyle">#style/NegativeButtonStyle</item>
<item name="buttonBarPositiveButtonStyle">#style/PositiveButtonStyle</item>
</style>
<style name="NegativeButtonStyle" parent="Widget.MaterialComponents.Button.TextButton.Dialog">
<item name="android:color">#color/colorPrimary</item>
</style>
<style name="PositiveButtonStyle" parent="Widget.MaterialComponents.Button.TextButton.Dialog">
<item name="android:color">#color/colorPrimary</item>
</style>
CheckoutFragment.kt
private fun createConfirmOrderDialog() {
val builder = AlertDialog.Builder(requireContext(), R.style.AlertDialogTheme)
builder.setTitle(getString(R.string.confirm_order))
.setMessage(dialogPrompt)
.setPositiveButton(R.string.confirm) { dialog, _ ->
viewModel.placeOrder()
dialog.dismiss()
}
.setNegativeButton(R.string.cancel) { dialog, _ ->
dialog.dismiss()
}
builder.show()
}
colors.xml
<color name="colorAccent">#F1CB1A</color> // I have this added to the base theme
This setup, however, shows a dialog where the button text is not visible since both text and background is white.
How can I fix this?
Use the MaterialAlertDialogBuilder instead of AlertDialog.Builder:
MaterialAlertDialogBuilder(context)
.setTitle("Title")
.setMessage(dialogPrompt)
.setPositiveButton("OK",listener)
.show()
The default color of the buttons is based on the colorPrimary color.
If you want to use a custom color you can use:
MaterialAlertDialogBuilder(context,R.style.AlertDialogTheme)
with this style
<style name="AlertDialogTheme" parent="ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<item name="buttonBarNegativeButtonStyle">#style/NegativeButtonStyle</item>
<item name="buttonBarPositiveButtonStyle">#style/PositiveButtonStyle</item>
</style>
<style name="NegativeButtonStyle" parent="Widget.MaterialComponents.Button.TextButton.Dialog">
<item name="android:textColor">#color/.....</item>
</style>
<style name="PositiveButtonStyle" parent="Widget.MaterialComponents.Button.TextButton.Dialog">
<item name="android:textColor">#color/....</item>
</style>
How can I get the popup menu which I see throughout the app otherwise (see below)? I tried experimenting with popupMenuStyleand popupMenuBackground but nothing changes.
AlertDialog.Builder builder = new AlertDialog.Builder(activity, R.style.AlertDialogStyle);
...
builder.show();
AlertDialogStyle:
<style name="AlertDialogStyle" parent="Theme.AppCompat.DayNight.Dialog.Alert">
<item name="android:windowTitleStyle">#style/DialogTitleStyle</item>
<item name="android:background">#color/colorPrimary</item>
<!-- <item name="popupMenuStyle">#style/Widget.AppCompat.Light.PopupMenu</item>-->
<!-- <item name="popupMenuBackground">#color/red</item>-->
<item name="buttonBarNeutralButtonStyle">#style/DialogButtonNeutralStyle</item>
<item name="buttonBarNegativeButtonStyle">#style/DialogButtonStyle</item>
<item name="buttonBarPositiveButtonStyle">#style/DialogButtonStyle</item>
</style>
If I comment android:background, Popup Menu is OK:
Solved! Instead of using
<item name="android:background">#color/colorPrimary</item>
in my custom style, I should've used
<item name="android:windowBackground">#color/colorPrimary</item>
I have made my custom style for progress dialog, however it has weird borders around it.
Here is the theme:
<style name="AppTheme.Dialog" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#android:color/white</item>
<item name="android:textColorPrimary">#android:color/white</item>
<item name="android:background">#color/colorPrimaryDark</item>
<item name="android:popupBackground">#null</item>
</style>
Any ideas why there is such weird background ?
To remove the colored or white border around the progress dialog have the dialog use a theme that defines a transparent windowBackground
<style name="MyDialogTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="android:windowBackground">#android:color/transparent</item>
</style>
When creating the dialog use this theme:
new ProgressDialog(MyActivity.this, R.style.MyDialogTheme);
Please add:
your_progress_dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
to your java.
Hope this helps!
it's related to this question.
But in contrary to alert dialog there is no AppCompat support to ProgressDialog.
I didn't manage to solve the problem , its possible to use the deprected THEME_HOLO_LIGHT
ProgressDialog dialog= new ProgressDialog(this,ProgressDialog.THEME_HOLO_LIGHT);
but you loose all the benefits of AppCompat (like color accent).
Create Two Style
1) API Level less then equal 19
<style name="AppAlertTheme19" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#color/btngreen</item>
<item name="android:textColorPrimary">#color/transparent</item>
<item name="android:background">#color/transparent</item>
<item name="android:windowBackground">#color/transparent</item>
<item name="android:popupBackground">#null</item>
</style>
2) API Level greater than 19
<style name="AppAlertTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#color/btngreen</item>
<item name="android:textColorPrimary">#color/transparent</item>
<item name="android:background">#color/white</item>
<item name="android:windowBackground">#color/transparent</item>
<item name="android:popupBackground">#null</item>
</style>
3)and init progress view like this
public class ProgressDialogCustom extends ProgressDialog {
public ProgressDialogCustom(Context context) {
super(context, getStyle());
setMessage("Please Wait ...");
setCancelable(false);
}
private static int getStyle() {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
return R.style.AppAlertTheme;
} else {
return R.style.AppAlertTheme19;
}
}
}
I may be late to answer this question, but as I was facing same problem, I resolved it as follows:
I created 2 styles one for above lollipop and one for below it.
API Level greater than 19
<style name="AppAlertTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#color/white</item>
<item name="android:textColorPrimary">#color/transparent</item>
<item name="android:background">#color/blue</item>
<item name="android:windowBackground">#color/transparent</item>
<item name="android:popupBackground">#null</item>
</style>
API Level less than 19
<style name="AppAlertTheme_api19" parent="android:Theme.Holo.Dialog">
<item name="android:alertDialogStyle">#style/CustomAlertDialogStyle</item>
<item name="android:windowBackground">#color/nlue</item>
<item name="android:background">#android:color/transparent</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:textColor">#color/white</item>
</style>
<style name="CustomAlertDialogStyle">
<item name="android:bottomBright">#android:color/transparent</item>
<item name="android:bottomDark">#android:color/transparent</item>
<item name="android:bottomMedium">#android:color/transparent</item>
<item name="android:centerBright">#android:color/transparent</item>
<item name="android:centerDark">#android:color/transparent</item>
<item name="android:centerMedium">#android:color/transparent</item>
<item name="android:fullBright">#android:color/transparent</item>
<item name="android:fullDark">#android:color/transparent</item>
<item name="android:topBright">#android:color/transparent</item>
<item name="android:topDark">#android:color/transparent</item>
</style>
Then used this style as follows:
public int getProgressDailogStyle(){
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
return R.style.AppAlertTheme;
} else {
return R.style.AppAlertTheme_api19;
}
}
and finally
progressDialog = new ProgressDialog(context, getProgressDailogStyle());
Hope this helps you..
I've added the appCompat material design to my app and it seems that the alert dialogs are not using my primary, primaryDark, or accent colors.
Here is my base style:
<style name="MaterialNavyTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/apptheme_color</item>
<item name="colorPrimaryDark">#color/apptheme_color_dark</item>
<item name="colorAccent">#color/apptheme_color</item>
<item name="android:textColorPrimary">#color/action_bar_gray</item>
</style>
Based on my understanding the dialogs button text should also use these colors. Am I wrong on my understanding or is there something more I need to do?
Solution:
The marked answer got me on the right track.
<style name="MaterialNavyTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/apptheme_color</item>
<item name="colorPrimaryDark">#color/apptheme_color_dark</item>
<item name="colorAccent">#color/apptheme_color</item>
<item name="android:actionModeBackground">#color/apptheme_color_dark</item>
<item name="android:textColorPrimary">#color/action_bar_gray</item>
<item name="sdlDialogStyle">#style/DialogStyleLight</item>
<item name="android:seekBarStyle">#style/SeekBarNavyTheme</item>
</style>
<style name="StyledDialog" parent="Theme.AppCompat.Light.Dialog">
<item name="colorPrimary">#color/apptheme_color</item>
<item name="colorPrimaryDark">#color/apptheme_color_dark</item>
<item name="colorAccent">#color/apptheme_color</item>
</style>
UPDATED ON Aug 2019 WITH The Material components for android library:
With the new Material components for Android library you can use the new com.google.android.material.dialog.MaterialAlertDialogBuilder class, which extends from the existing androidx.appcompat.AlertDialog.Builder class and provides support for the latest Material Design specifications.
Just use something like this:
new MaterialAlertDialogBuilder(context)
.setTitle("Dialog")
.setMessage("Lorem ipsum dolor ....")
.setPositiveButton("Ok", /* listener = */ null)
.setNegativeButton("Cancel", /* listener = */ null)
.show();
You can customize the colors extending the ThemeOverlay.MaterialComponents.MaterialAlertDialog style:
<style name="CustomMaterialDialog" parent="#style/ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<!-- Background Color-->
<item name="android:background">#006db3</item>
<!-- Text Color for title and message -->
<item name="colorOnSurface">#color/secondaryColor</item>
<!-- Text Color for buttons -->
<item name="colorPrimary">#color/white</item>
....
</style>
To apply your custom style just use the constructor:
new MaterialAlertDialogBuilder(context, R.style.CustomMaterialDialog)
To customize the buttons, the title and the body text check this post for more details.
You can also change globally the style in your app theme:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light">
...
<item name="materialAlertDialogTheme">#style/CustomMaterialDialog</item>
</style>
WITH SUPPORT LIBRARY and APPCOMPAT THEME:
With the new AppCompat v22.1 you can use the new android.support.v7.app.AlertDialog.
Just use a code like this:
import android.support.v7.app.AlertDialog
AlertDialog.Builder builder =
new AlertDialog.Builder(this, R.style.AppCompatAlertDialogStyle);
builder.setTitle("Dialog");
builder.setMessage("Lorem ipsum dolor ....");
builder.setPositiveButton("OK", null);
builder.setNegativeButton("Cancel", null);
builder.show();
And use a style like this:
<style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">#FFCC00</item>
<item name="android:textColorPrimary">#FFFFFF</item>
<item name="android:background">#5fa3d0</item>
</style>
Otherwise you can define in your current theme:
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- your style -->
<item name="alertDialogTheme">#style/AppCompatAlertDialogStyle</item>
</style>
and then in your code:
import android.support.v7.app.AlertDialog
AlertDialog.Builder builder =
new AlertDialog.Builder(this);
Here the AlertDialog on Kitkat:
when initializing dialog builder, pass second parameter as the theme. It will automatically show material design with API level 21.
AlertDialog.Builder builder = new AlertDialog.Builder(this, AlertDialog.THEME_DEVICE_DEFAULT_DARK);
or,
AlertDialog.Builder builder = new AlertDialog.Builder(this, AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
AppCompat doesn't do that for dialogs (not yet at least)
EDIT: it does now. make sure to use android.support.v7.app.AlertDialog
Material Design styling alert dialogs: Custom Font, Button, Color & shape,..
MaterialAlertDialogBuilder(requireContext(),
R.style.MyAlertDialogTheme
)
.setIcon(R.drawable.ic_dialogs_24px)
.setTitle("Feedback")
//.setView(R.layout.edit_text)
.setMessage("Do you have any additional comments?")
.setPositiveButton("Send") { dialog, _ ->
val input =
(dialog as AlertDialog).findViewById<TextView>(
android.R.id.text1
)
Toast.makeText(context, input!!.text, Toast.LENGTH_LONG).show()
}
.setNegativeButton("Cancel") { _, _ ->
Toast.makeText(requireContext(), "Clicked cancel", Toast.LENGTH_SHORT).show()
}
.show()
Style:
<style name="MyAlertDialogTheme" parent="Theme.MaterialComponents.DayNight.Dialog.Alert">
<item name="android:textAppearanceSmall">#style/MyTextAppearance</item>
<item name="android:textAppearanceMedium">#style/MyTextAppearance</item>
<item name="android:textAppearanceLarge">#style/MyTextAppearance</item>
<item name="buttonBarPositiveButtonStyle">#style/Alert.Button.Positive</item>
<item name="buttonBarNegativeButtonStyle">#style/Alert.Button.Neutral</item>
<item name="buttonBarNeutralButtonStyle">#style/Alert.Button.Neutral</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="shapeAppearanceOverlay">#style/ShapeAppearanceOverlay.MyApp.Dialog.Rounded
</item>
</style>
<style name="MyTextAppearance" parent="TextAppearance.AppCompat">
<item name="android:fontFamily">#font/rosarivo</item>
</style>
<style name="Alert.Button.Positive" parent="Widget.MaterialComponents.Button.TextButton">
<!-- <item name="backgroundTint">#color/colorPrimaryDark</item>-->
<item name="backgroundTint">#android:color/transparent</item>
<item name="rippleColor">#color/colorAccent</item>
<item name="android:textColor">#color/colorPrimary</item>
<!-- <item name="android:textColor">#android:color/white</item>-->
<item name="android:textSize">14sp</item>
<item name="android:textAllCaps">false</item>
</style>
<style name="Alert.Button.Neutral" parent="Widget.MaterialComponents.Button.TextButton">
<item name="backgroundTint">#android:color/transparent</item>
<item name="rippleColor">#color/colorAccent</item>
<item name="android:textColor">#color/colorPrimary</item>
<!--<item name="android:textColor">#android:color/darker_gray</item>-->
<item name="android:textSize">14sp</item>
<item name="android:textAllCaps">false</item>
</style>
<style name="ShapeAppearanceOverlay.MyApp.Dialog.Rounded" parent="">
<item name="cornerFamily">rounded</item>
<item name="cornerSize">8dp</item>
</style>
Output:
You could use
Material Design Library
Material Design Library made for pretty alert dialogs, buttons, and other things like snack bars. Currently it's heavily developed.
Guide, code, example - https://github.com/navasmdc/MaterialDesignLibrary
Guide how to add library to Android Studio 1.0 - How do I import material design library to Android Studio?
.
Happy coding ;)
You can consider this project:
https://github.com/fengdai/AlertDialogPro
It can provide you material theme alert dialogs almost the same as lollipop's. Compatible with Android 2.1.
For some reason the android:textColor only seems to update the title color.
You can change the message text color by using a
SpannableString.AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.MyDialogTheme));
AlertDialog dialog = builder.create();
Spannable wordtoSpan = new SpannableString("I know just how to whisper, And I know just how to cry,I know just where to find the answers");
wordtoSpan.setSpan(new ForegroundColorSpan(Color.BLUE), 15, 30, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
dialog.setMessage(wordtoSpan);
dialog.show();
Try this library:
https://github.com/avast/android-styled-dialogs
It's based on DialogFragments instead of AlertDialogs (like the one from #afollestad). The main advantage: Dialogs don't dismiss after rotation and callbacks still work.
I've breaking my head over this quite a bit. What I need to do is, change the style of all AlertDialogs in my android application - dialog background needs to be white-ish, and text needs to be black-ish. I tried creating a lot of styles, themes, and applying from the code, manifest, etc, but no success, with regard to the text colors inside the AlertDialog. Right now, I have the simplest of codes, set like this:
Manifest:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
styles.xml:
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:alertDialogStyle">#style/DialogStyle</item>
</style>
<style name="DialogStyle" parent="#android:style/Theme.Dialog">
<!-- changing these background stuff works fine -->
<item name="android:bottomBright">#android:color/white</item>
<item name="android:bottomDark">#android:color/white</item>
<item name="android:bottomMedium">#drawable/dialog_footer_bg</item>
<item name="android:centerBright">#android:color/white</item>
<item name="android:centerDark">#drawable/dialog_body_bg</item>
<item name="android:centerMedium">#android:color/white</item>
<item name="android:fullBright">#color/orange</item>
<item name="android:fullDark">#color/orange</item>
<item name="android:topBright">#color/green</item>
<item name="android:topDark">#drawable/dialog_header_bg</item>
The items listed below don't work (please read the comments I've put above each element):
<!-- panelBackground is not getting set to null, there is something squarish around it -->
<item name="android:panelBackground">#null</item>
<!-- Setting this textColor doesn't seem to have any effect at all. Messages, title, button text color, whatever; nothing changes. -->
<item name="android:textColor">#000000</item>
<!-- Also tried with textAppearance, as follows. Didn't work -->
<item name="android:textAppearance">?android:attr/textColorPrimaryInverse</item>
<!-- Also tried changing textAppearancePrimary, to no avail -->
<item name="android:textColorPrimary">#000000</item>
<!-- Also need to change the dialog title text, tried it as follows, dint work: -->
<item name="android:windowTitleStyle">#style/DialogWindowTitle</item>
</style>
The DialogWindowTitle is defined as follows:
<style name="DialogWindowTitle">
<item name="android:textAppearance">?android:attr/textAppearanceMediumInverse</item>
</style>
So none of these is working. Can anyone tell me what I could be doing wrong, and how can I:
Change text color for messages (content text)
Change title text color
Remove the
panel background
Note: I need to support API 8 (2.2) upwards. Also, I've went through most of the related question here, and google groups, but can't figure out, though I have a feeling its right under my nose!
Edit: adding screenshot:
You need to define a Theme for your AlertDialog and reference it in your Activity's theme. The attribute is alertDialogTheme and not alertDialogStyle. Like this:
<style name="Theme.YourTheme" parent="#android:style/Theme.Holo">
...
<item name="android:alertDialogTheme">#style/YourAlertDialogTheme</item>
</style>
<style name="YourAlertDialogTheme">
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowAnimationStyle">#android:style/Animation.Dialog</item>
<item name="android:windowMinWidthMajor">#android:dimen/dialog_min_width_major</item>
<item name="android:windowMinWidthMinor">#android:dimen/dialog_min_width_minor</item>
<item name="android:windowTitleStyle">...</item>
<item name="android:textAppearanceMedium">...</item>
<item name="android:borderlessButtonStyle">...</item>
<item name="android:buttonBarStyle">...</item>
</style>
You'll be able to change color and text appearance for the title, the message and you'll have some control on the background of each area. I wrote a blog post detailing the steps to style an AlertDialog.
Remove the panel background
<item name="android:windowBackground">#color/transparent_color</item>
<color name="transparent_color">#00000000</color>
This is Mystyle:
<style name="ThemeDialogCustom">
<item name="android:windowFrame">#null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowAnimationStyle">#android:style/Animation.Dialog</item>
<item name="android:windowBackground">#color/transparent_color</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:colorBackgroundCacheHint">#null</item>
</style>
Which i have added to the constructor.
Add textColor :
<item name="android:textColor">#ff0000</item>
Here's my Code to theme the alert dialog box:
<style name="alertDialog" parent="Theme.AppCompat.Dialog.Alert">
<item name="android:background">#color/light_button_text_color</item>
<item name="android:textColor">#android:color/black</item>
<item name="android:textColorPrimary">#android:color/black</item>
<item name="android:textColorSecondary">#android:color/black</item>
<item name="android:titleTextColor" tools:targetApi="m">#android:color/black</item>
</style>
Place this code in styles.xml.
In your java apply this theme as:
AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.alertDialog);
Output of the code
You have to add the style to the constructor of the dialog
builder = new AlertDialog.Builder(this, R.style.DialogStyle);
I changed color programmatically in this way :
var builder = new AlertDialog.Builder (this);
...
...
...
var dialog = builder.Show ();
int textColorId = Resources.GetIdentifier ("alertTitle", "id", "android");
TextView textColor = dialog.FindViewById<TextView> (textColorId);
textColor?.SetTextColor (Color.DarkRed);
as alertTitle, you can change other data by this way (next example is for titleDivider):
int titleDividerId = Resources.GetIdentifier ("titleDivider", "id", "android");
View titleDivider = dialog.FindViewById (titleDividerId);
titleDivider?.SetBackgroundColor (Color.Red);
this is in C#, but in java it is the same.
It depends how much you want to customize the alert dialog. I have different steps in order to customize the alert dialog. Please visit: https://stackoverflow.com/a/33439849/5475941
Building on #general03's answer, you can use Android's built-in style to customize the dialog quickly. You can find the dialog themes under android.R.style.Theme_DeviceDefault_Dialogxxx.
For example:
builder = new AlertDialog.Builder(this, android.R.style.Theme_DeviceDefault_Dialog_MinWidth);
builder = new AlertDialog.Builder(this, android.R.style.Theme_DeviceDefault_Dialog_NoActionBar);
builder = new AlertDialog.Builder(this, android.R.style.Theme_DeviceDefault_DialogWhenLarge);
Use this in your Style in your values-v21/style.xml
<style name="AlertDialogCustom" parent="#android:style/Theme.Material.Dialog.NoActionBar">
<item name="android:windowBackground">#android:color/white</item>
<item name="android:windowActionBar">false</item>
<item name="android:colorAccent">#color/cbt_ui_primary_dark</item>
<item name="android:windowTitleStyle">#style/DialogWindowTitle.Sphinx</item>
<item name="android:textColorPrimary">#color/cbt_hints_color</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowMinWidthMajor">#android:dimen/dialog_min_width_major</item>
<item name="android:windowMinWidthMinor">#android:dimen/dialog_min_width_minor</item>
</style>
And for pre lollipop devices put it in values/style.xml
<style name="AlertDialogCustom" parent="#android:style/Theme.Material.Dialog.NoActionBar">
<item name="android:windowBackground">#android:color/white</item>
<item name="android:windowActionBar">false</item>
<item name="android:colorAccent">#color/cbt_ui_primary_dark</item>
<item name="android:windowTitleStyle">#style/DialogWindowTitle.Sphinx</item>
<item name="android:textColorPrimary">#color/cbt_hints_color</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowMinWidthMajor">#android:dimen/dialog_min_width_major</item>
<item name="android:windowMinWidthMinor">#android:dimen/dialog_min_width_minor</item>
</style>
<style name="DialogWindowTitle.Sphinx" parent="#style/DialogWindowTitle_Holo">
<item name="android:textAppearance">#style/TextAppearance.Sphinx.DialogWindowTitle</item>
</style>
<style name="TextAppearance.Sphinx.DialogWindowTitle" parent="#android:style/TextAppearance.Holo.DialogWindowTitle">
<item name="android:textColor">#color/dark</item>
<!--<item name="android:fontFamily">sans-serif-condensed</item>-->
<item name="android:textStyle">bold</item>
</style>