Show entire bottom sheet with EditText above Keyboard

后端 未结 8 1354
北恋
北恋 2020-11-30 21:27

I\'m implementing a UI where a bottom sheet will appear above the keyboard with an EditText for the user to enter a value. The problem is the View is being partially overlap

8条回答
  •  情深已故
    2020-11-30 21:54

    dialog = new BottomSheetDialog(getContext(), R.style.BottomSheetDialog);  
    dialog.setOnShowListener(new DialogInterface.OnShowListener() {
    @Override
    public void onShow(DialogInterface dialog) {
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        BottomSheetDialog d = (BottomSheetDialog) dialog;
                        FrameLayout bottomSheet = d.findViewById(R.id.design_bottom_sheet);
                        BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);
                        bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
                    }
                },0);
            }
        });
    

    This code works fine at Fragment's onCreateView method (thanks for ADM)

提交回复
热议问题