我使用 AlertDialog 来提醒用户确认删除.我检查了我的设备(Android 5.1),它显示良好
I used AlertDialog to alert user confirm delete. I check on my device (Android 5.1) and it show well
但在其他一些设备上(也运行 Android 5.1),对话框错过了正负按钮.
But on some another device (also run Android 5.1), the dialog missed positive and negative button.
我检查并发现发生此问题的设备具有中等分辨率(960x540、854x480).
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 ?
我的显示对话框代码:
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>
所以按钮就在那里.不幸的是,它们是白色背景上的白色文本.它与分辨率无关,而与您选择的主题有关.要解决这个问题,您需要在对话框主题中设置正确的文本颜色.
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.
例如在styles.xml中添加
For example, in styles.xml add
<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);
希望这会有所帮助.
这篇关于AlertDialog 不显示正负按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!