尝试使用底部表单中的弹出窗口(Android)



我正试图从我的应用程序中的BottomSheet打开一个弹出窗口,我希望它在底部工作表上方打开。

这是我的密码。

private void setUpPriorityPopUpWindow()
{
LayoutInflater inflater = (LayoutInflater) requireContext().getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
@SuppressLint("InflateParams") View v = inflater.inflate(R.layout.tasks_priority_popup_window,null);
tasksPriorityPopUp = new PopupWindow(v, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT,true);
}

在我的BottomSheetFragment:的OnCreateView中

ImageButton priority = v.findViewById(R.id.priority);
setUpPriorityPopUpWindow();
priority.setOnClickListener(new View.OnClickListener() {
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public void onClick(View v) {
tasksPriorityPopUp.showAsDropDown(v);
}
});

任何形式的帮助都将不胜感激。

编辑:它目前在BottomSheet 后面打开

您应该使用DialogDialogFragment,而不是膨胀视图。

new AlertDialog.Builder(context)
.setTitle("Delete entry")
.setMessage("Are you sure you want to delete this entry?")
// Specifying a listener allows you to take an action before dismissing the dialog.
// The dialog is automatically dismissed when a dialog button is clicked.
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) { 
// Continue with delete operation
}
})
// A null listener allows the button to dismiss the dialog and take no further action.
.setNegativeButton(android.R.string.no, null)
.setIcon(android.R.drawable.ic_dialog_alert)
.show();
class PurchaseConfirmationDialogFragment : DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog =
AlertDialog.Builder(requireContext())
.setMessage(getString(R.string.order_confirmation))
.setPositiveButton(getString(R.string.ok)) { _,_ -> }
.create()
companion object {
const val TAG = "PurchaseConfirmationDialog"
}
}

最新更新