Keyboard hiding EditTexts in Fragments

后端 未结 9 782
长情又很酷
长情又很酷 2020-12-25 13:59

edit: I need to use the keyboard, but it hides my EditText, I need it to scroll so the keyboard is not hiding it.

I am using a Samsun

相关标签:
9条回答
  • 2020-12-25 14:36

    I solved the problem by installing another soft keyboard, via the google play store.

    It was Petey's comments that made me explore this solution.

    The IME you used has it's own "floating" layout, can you try your code with built-in IMEs like Google Keyboard or set your IME to a normal full-width layout?

    So I figured, no amount of playing with the view layout was going to affect a soft keyboard that has an independent layout.

    I used this link https://code.google.com/p/softkeyboard/wiki/HowTo

    It even works with Android Manifest:

    android:windowSoftInputMode="stateHidden"
    

    I then use imeoptions to control the flow of the editor cursor within the view.

    edit update

    I just tried the app on a no-brand android tablet, which comes with comes with a generic android keyboard and it works, without having to change a thing. It seems the Samsung default keyboard is painful.

    0 讨论(0)
  • 2020-12-25 14:36

    I have tried this code and resolve my issue.

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
    
    0 讨论(0)
  • 2020-12-25 14:38

    Try to call InputMethodManager.hideSoftInputFromWindow() during your fragment's onActivityCreated() function mentioned in this SO answer?

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        AppUtil.hideKeyboard(getActivity(), getView());
    }
    

    where hideKeyboard() looks like this

    public static void hideKeyboard(Activity activity, View viewToHide) {
        InputMethodManager imm = (InputMethodManager) activity
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(viewToHide.getWindowToken(), 0);
    }
    
    0 讨论(0)
提交回复
热议问题