I updated my phone to Android 6.0 and I have these 2 problems with dialogs:
1)The title is shown but the messages isn\'t for alert dialog(SOLVED):
Just put this in your styles file inside your Base Theme style tag and you are good to go
<item name="android:alertDialogTheme">@style/Theme.AppCompat.Light.Dialog.Alert</item>
I suspect that you are ending up showing white text on a white background! (Looking at the screenshot, the (i) icon is not showing up well either, suggesting that it was designed to be shown on a background other than white.
You can use the constructor public AlertDialog.Builder (Context context, int themeResId)
to ensure you are using a specific theme to style your dialog, where the Theme_Material_Dialog
is probably what you want.
new AlertDialog.Builder(context)
.setTitle("Delete entry")
.setMessage("Are you sure you want to delete this entry?")
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// continue with delete
}
})
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// do nothing
}
})
.setIcon(android.R.drawable.ic_dialog_alert)
.show();
Hope this will help you.............
In my case all dialogs had the same color as fonts (title & message). What I have done to fix this state was the change of the color attribute in my theme. I copied the xml theme file into the 'res/values-v22' and set different color for marshmallow.
<resources>
<style name="LywCompatTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
<item name="android:textColorPrimary">@android:color/tertiary_text_dark</item>
</style>
</resources>
or only for dialogs
<resources>
<style name="LywCompatTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
<item name="android:alertDialogTheme">@style/LywAlertDialogStyle</item>
</style>
<style name="LywAlertDialogStyle" parent="Base.Theme.AppCompat.Light.Dialog.Alert">
<item name="android:textColorPrimary">@color/lyw_secondary_text_color</item>
</style>
</resources>
Use constructor with theme for Lollipop and newer android versions:
Dark theme
AlertDialog.Builder builder;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder = new AlertDialog.Builder(context, android.R.style.Theme_Material_Dialog_Alert);
} else {
builder = new AlertDialog.Builder(context);
}
And for Light theme
AlertDialog.Builder builder;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder = new AlertDialog.Builder(context, android.R.style.Theme_Material_Light_Dialog_Alert);
} else {
builder = new AlertDialog.Builder(context);
}
Maybe your main text color is the same as dialog background color, in that case in your styles.xml use (just an example):
<style name="AlertDialog" parent="@android:style/Theme.Material.Light.Dialog.Alert">
<item name="android:textColor">#000000</item>
</style>
and in dialog creation:
new AlertDialog.Builder(
new ContextThemeWrapper(getContext(), R.style.AlertDialog))
).setMessage("test");