Bottom Sheet Fragment comes up with keyboard

前端 未结 7 1753
野的像风
野的像风 2020-12-04 14:37

I have an edit text inside a bottom sheet fragment. when the focus come on the edit text the layout goes up . i tried

 android:windowSoftInputMode=\"adjustNo         


        
相关标签:
7条回答
  • 2020-12-04 15:22

    Use this in your Dialog Fragment.

    getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    

    Inside onCreateView like this.

    @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    
            View rootView = inflater.inflate(R.layout.dialog_fragment, container);
    
            //set to adjust screen height automatically, when soft keyboard appears on screen 
            getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    
    
            return rootView;
        }
    

    EDIT 1:

    I have made some changes with what layout you are using make it apply in your current layout.

    Here is layout.

    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/bottom_sheet"
        android:layout_width="match_parent"
        android:layout_height="400dp"
        android:layout_gravity="bottom"
        android:background="@android:color/holo_blue_light"
        android:padding="10dp"
        app:behavior_hideable="true"
        app:behavior_peekHeight="60dp"
        app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
    
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true"
            android:isScrollContainer="false"
            android:scrollbars="vertical">
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">
    
                <EditText
                    android:id="@+id/edt"
                    android:layout_width="match_parent"
                    android:layout_height="40dp"
                    android:background="@android:color/white"
                    android:padding="10dp" />
    
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="250dp"
                    android:layout_below="@+id/edt" />
    
            </LinearLayout>
    
    
        </ScrollView>
    
    </FrameLayout>
    

    Here is Fragment.

    public class TestFragment extends BottomSheetDialogFragment {
    
        @Nullable
        @Override
        public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
            View v = inflater.inflate(R.layout.test4, container, false);
            return v;
        }
    

    EDIT 2:

    You can try android:elevation="50dp" property for shadow above Bottom Sheet give a try with that in frame layout.

    0 讨论(0)
  • 2020-12-04 15:22

    I have faced the same scenario, Instead of EditText I used SearchView.A keyboard was not hidden when BottomSheetDialog goes to the hidden state.

    Simply call this search_channel_template.clearFocus();

    I will share my code which I was used to hiding the Keyboard.

    search_channel_template = (SearchView) bottomSheetDialog.findViewById(R.id.search_channel_template);
    
    txtVw_template_headerBS_down_id.setOnClickListener(new OnSingleClickListener() {
                @Override
                public void onSingleClick(View v) {
                    search_channel_template.clearFocus();
                    bottomSheetDialog.getBehavior().setState(BottomSheetBehaviorv2.STATE_HIDDEN);
                }
            });
    
    0 讨论(0)
  • 2020-12-04 15:23

    Replace your flag from

    adjustNothing

    to

    adjustPan

    Check the Official Document

    0 讨论(0)
  • 2020-12-04 15:24

    100% working formula for BottomSheetFragment

    Use this in onCreateDialog in BottomSheetFragment

    KeyboardUtil(getActivity(), view);
    

    or

    For fragment use

    new KeyboardUtil(this, findViewById(R.id.fragment_container));
    

    by using this Util class

    https://github.com/mikepenz/MaterialDrawer/blob/aa9136fb4f5b3a80460fe5f47213985026d20c88/library/src/main/java/com/mikepenz/materialdrawer/util/KeyboardUtil.java

    Credit:Mikepenz

    0 讨论(0)
  • 2020-12-04 15:25

    in the activity declaration in the manifest, put these lines of code:

    android:windowSoftInputMode="stateHidden"
    android:windowTranslucentNavigation="true"
    android:windowTranslucentStatus="true" 
    
    0 讨论(0)
  • 2020-12-04 15:27

    Seems like there is bug in the older design version. I encountered the same problem, but after I upgraded the design version, adjustnothing can work as expected.

    In gradle:

    com.android.support:design:26.1.0
    

    In your BottomSheetDialog:

    getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
    getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
    
    0 讨论(0)
提交回复
热议问题