我正在制作一个自定义的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及更高版本
发布评论