I used AlertDialog to alert user confirm delete. I check on my device (Android 5.1) and it show well
But on some another device (also run Android 5.1), the dialog missed positive and negative button.
I checked and found that devices happen this issue have a medium resolution (960x540, 854x480).
Is resolution relate with this issue ? If not, can you tell me the reason and how to fix this issue ?
My code for display dialog:
public static final Dialog yesNoDialog(Context context,
String message,
DialogInterface.OnClickListener yesAction, DialogInterface.OnClickListener noAction) {
AlertDialog.Builder builder = new AlertDialog.Builder(context,R.style.todoDialogLight);
builder.setTitle(context.getString(R.string.app_name))
.setMessage(message)
.setCancelable(false)
.setPositiveButton("YES", yesAction)
.setNegativeButton("NO", noAction);
return builder.create();
}
And styles.xml
<style name="todoDialogLight" parent="Theme.AppCompat.Light.Dialog">
<!-- Used for the buttons -->
<item name="colorAccent">@color/colorPrimaryDark</item>
<item name="android:textStyle">bold</item>
<!-- Used for the title and text -->
<item name="android:textColorPrimary">@color/colorText</item>
<!-- Used for the background -->
<!-- <item name="android:background">#4CAF50</item>-->
<item name="android:fontFamily">sans-serif</item>
<item name="android:windowAnimationStyle">@style/RemindDialogAnimation</item>
<item name="android:layout_width">@dimen/width_remind_dialog</item>
<item name="android:layout_height">wrap_content</item>
</style>
Ali's solution worked for me. My original code worked on previous android versions <7. But testing on my Pixel gave invisible buttons. I added the style concept detailed by Ali as shown below and all is well:
So the buttons are there for me. Unfortunately, they were white text on white background. It has nothing to do with the resolution but more to do with the theme you are choosing. To solve this you need to set the right text color in your dialog theme.
For example, in styles.xml add
and in your activity add
Hope this helps.
It is really relate to resolution, I do not know exact the reason and just make a if else condition to fix this issue.
AlertDialog
Hope it help for others developer who have the same problem.
Dialog dialog;
Add this in style.xml:
and in activity use
If you are using a custom theme in your
styles.xml
set the color ofcolorAccent
to a darker color.