DialogFragment按钮退出了屏幕API 24及更高版本

编程入门 行业动态 更新时间:2024-10-27 08:35:16
本文介绍了DialogFragment按钮退出了屏幕API 24及更高版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在制作一个自定义的DialogFragment,它显示可选择的数据列表.该列表太长,无法滚动显示在屏幕上.对于API 23之前的版本,一切似乎都可以正常工作,但是当我在API 24+上进行测试时,DialogFragment的按钮不再可见.我看着 AlertDialog上的缺少按钮| Android 7.0(Nexus 5x),但这似乎并不适用,因为当我减少列表中的内容量使其完全适合屏幕时,按钮会显示出来.如何使我的按钮可见?

I am making a custom DialogFragment that displays a selectable list of data. The list is too long to fit on the screen without scrolling. For up to API 23, everything seems to work fine, but when I test on API 24+, the DialogFragment's button's are no longer visible. I looked at Missing buttons on AlertDialog | Android 7.0 (Nexus 5x), but that doesn't seem to apply because my buttons do show up when I reduce the amount of content in the list so that it all fits on the screen. How can I make my buttons visible?

我的onCreateDialog()方法:

My onCreateDialog() method:

@NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); final View dialogView = View.inflate(getContext(), android.R.layout.select_dialog_multichoice, null); builder.setView(dialogView) .setTitle(R.string.muscle_groups) .setMultiChoiceItems(Exercise.MUSCLE_GROUPS, selectionTrackingArray, new DialogInterface.OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int which, boolean isChecked) { ... } }) .setPositiveButton(R.string.affirmative, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { ... } }) .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); return builder.create(); }

按钮似乎被推离了屏幕

让我知道是否需要更多信息.

Let me know if any more info is needed.

推荐答案

尽管示例代码未使用它,但您是否恰巧使用AlertDialog.Builder的setMessage()方法来设置消息?

Do you happen to set message by using setMessage() method of AlertDialog.Builder, although your sample code doesn't use it?

因为如果您的内容不适合屏幕,则同时为警报对话框生成器设置自定义视图和消息会产生上述副作用.

Because if you have a content that doesn't fit screen, setting a custom view and message at the same time to an alert dialog builder has a side effect as you described.

要解决此问题,请将您的消息添加到自定义视图,并且不要使用setMessage()方法设置消息文本,将显示对话框按钮.

To solve this issue add your message to your custom view, and don't set message text using setMessage() method, dialog buttons will be visible.

希望这会有所帮助.

更多推荐

DialogFragment按钮退出了屏幕API 24及更高版本

本文发布于:2023-11-27 01:29:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636014.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:出了   更高   按钮   屏幕   版本

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!