AlertDialog 不显示肯定和否定按钮

新手上路,请多包涵

我使用 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 许可协议

阅读 534
1 个回答

所以按钮是为我准备的。不幸的是,它们是白底白字。它与分辨率无关,但与您选择的主题有关。要解决这个问题,您需要在对话框主题中设置正确的文本颜色。

例如,在 styles.xml 中添加

<style name="MyDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorPrimary">@color/colorPrimaryDarkBlue</item>
</style>

并在您的活动中添加

AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(MyActivity.this, R.style.MyDialogTheme);

希望这可以帮助。

原文由 Ali 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题