简体   繁体   中英

DialogFragment buttons pushed off screen API 24 and above

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.

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.

The answer works for me. (I don't have enough points to upvote it so I can only chime in with a new answer.) In particular, instead of using setMessage() I now use setTitle().

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM