DialogFragment buttons pushed off screen API 24 and above

痞子三分冷 提交于 2020-04-11 18:34:11

问题


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?

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();
}

Buttons appear to be pushed off the screen

Let me know if any more info is needed.


回答1:


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.

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.

Hope this helps.



来源:https://stackoverflow.com/questions/44725164/dialogfragment-buttons-pushed-off-screen-api-24-and-above

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!