我使用 AlertDialog 来提醒用户确认删除。我检查了我的设备 (Android 5.1),它显示良好
但在另一台设备(也运行 Android 5.1)上,对话框缺少肯定和否定按钮。
我检查并发现发生此问题的设备具有中等分辨率(960x540、854x480)。
分辨率与此问题有关吗?如果没有,你能告诉我原因以及如何解决这个问题吗?
我的显示对话框代码:
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();
}
和 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>
原文由 CauCuKien 发布,翻译遵循 CC BY-SA 4.0 许可协议
所以按钮是为我准备的。不幸的是,它们是白底白字。它与分辨率无关,但与您选择的主题有关。要解决这个问题,您需要在对话框主题中设置正确的文本颜色。
例如,在 styles.xml 中添加
并在您的活动中添加
希望这可以帮助。