BottomSheetDialogFragment里面的Fragment问题

时间:2019-11-25 14:08:18

标签: android-fragments dialog bottom-sheet

在Fragment中显示BottomSheetDialogFragment并与特定按钮交互(例如,按照下面的图片增加价格)后,Fragment消失并按照第二张照片显示。

代码:

increase_price.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String coun_cost = shipment_price.getText().toString();

            if (coun_cost.isEmpty()) {
                counter_price = 0;
                counter_price = counter_price + 5;
                requestFocus(shipment_price);
                shipment_price.setText(String.valueOf(counter_price));
            } else {
                counter_price = Integer.valueOf(coun_cost);
                counter_price = counter_price + 5;
                requestFocus(shipment_price);
                shipment_price.setText(String.valueOf(counter_price));
            }
        }
    });

    decrement_price.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String coun_cost = shipment_price.getText().toString();

            if (!coun_cost.isEmpty()) {
                counter_price = Integer.valueOf(coun_cost);
                counter_price = counter_price - 5;
                if (counter_price >= 0) {
                    requestFocus(shipment_price);
                    shipment_price.setText(String.valueOf(counter_price));
                } else {
                    counter_price = 0;
                    requestFocus(shipment_price);
                    shipment_price.setText(String.valueOf(counter_price));
                }
            }
        }
    });

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:0)

删除下面的代码行后,我解决了问题。

    param = Objects.requireNonNull(getActivity()).getWindow().getAttributes();
    param.width = WindowManager.LayoutParams.MATCH_PARENT;
    param.height = WindowManager.LayoutParams.DIM_AMOUNT_CHANGED;