Keyboard hiding EditTexts in Fragments

后端 未结 9 781
长情又很酷
长情又很酷 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:15

    Change this to LinearLayout:

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    

    to

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:orientation="vertical"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin">
    

    (and the closing tag). Note the orientation.

    Update the manifest Remove this:

    <application ... >
        <activity
          android:windowSoftInputMode="stateVisible|adjustResize|adjustPan">
            ...
        </activity>
        ...
    </application>
    

    Change this (height):

    <ScrollView
        android:layout_height="wrap_content"
        android:layout_width="match_parent">
    
    0 讨论(0)
  • 2020-12-25 14:20

    Try to use WindowsSoftInputMode as adjustpan only.

    For ex:

    android:windowSoftInputMode="adjustPan" 
    
    0 讨论(0)
  • 2020-12-25 14:23

    Before show your Snackbar widget hide the keyboard like this,

    public void showSnackBar(){ 
    InputMethodManager manager = (InputMethodManager)getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
    manager.hideSoftInputFromWindow(getView().getWindowToken(),0); 
    Snackbar snackbar = Snackbar.make(getView(), "Some message!", Snackbar.LENGTH_INDEFINITE).show(); 
    }
    
    0 讨论(0)
  • 2020-12-25 14:25

    What worked for me was using the ScrollView the same way as you in my FrameLayout, in which I added this property: android:windowSoftInputMode="adjustPan". At the end, it looks like this and it is working. I did not need to change anything programatically:

     <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".ProductFragment"
        android:windowSoftInputMode="adjustPan">
    
        <ScrollView
            android:layout_height="wrap_content"
            android:layout_width="match_parent">
          ...
        </ScrollView>
    </FrameLayout>
    
    0 讨论(0)
  • 2020-12-25 14:34

    You can try to put this in onActivityCreated of your fragment:

    getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
    

    This should not make the keyboard upon loading or starting of your activity with fragment.

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

    keep in mind that hide keyboard does not work with getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

    0 讨论(0)
提交回复
热议问题