Android: How do I prevent the soft keyboard from pushing my view up?

后端 未结 28 1190
南笙
南笙 2020-11-22 05:10

I have a vertical sliding drawer at the bottom of my app. When the soft keyboard opens, it pushes the tab for the drawer up, so it sits atop the keyboard. I actually want it

相关标签:
28条回答
  • 2020-11-22 05:44

    When you want to hide view when open keyboard.

    Add this into your Activity in manifest file

    android:windowSoftInputMode="stateHidden|adjustPan"
    
    0 讨论(0)
  • 2020-11-22 05:46

    For xamarin users add this code to Activity attribute of the MainActivity class,

    WindowSoftInputMode =Android.Views.SoftInput.AdjustNothing
    

    or you can add this code Window.SetSoftInputMode(Android.Views.SoftInput.AdjustNothing) to the OnCreate method of MainActivity class.

    0 讨论(0)
  • 2020-11-22 05:46

    This code may help you. Use it in your oncreate method.

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
    
    0 讨论(0)
  • 2020-11-22 05:48

    For Scroll View:

    if after adding android:windowSoftInputMode="stateHidden|adjustPan" in your Android Manifest and still does not work.

    It may be affected because when the keyboard appears, it will be into a scroll view and if your button/any objects is not in your scroll view then the objects will follow the keyboard and move its position.

    Check out your xml where your button is and make sure it is under your scroll View bracket and not out of it.

    Hope this helps out. :D

    0 讨论(0)
  • 2020-11-22 05:49

    You can simply switch your Activity's windowSoftInputModeflag to adjustPan in your AndroidMainfest.xml file inside your activity tag.

    Check the official documentation for more info.

    <activity
       ...
       android:windowSoftInputMode="adjustPan"> 
    </activity>
    

    If your container is not changing size, then you likely have the height set to "match parent". If possible, set the parent to "Wrap Content", or a constraint layout with constraingts to top and bottom of parent.

    The parent container will shrink to fit the available space, so it is likely that your content should be inside of a scolling view to prevent (depending on the phone manufacturer and the layout choosen...)

    1. Content being smashed together
    2. Content hanging off the screen
    3. Content being inacccessable due to it being underneath the keyboard

    even if the layout it is in is a relative or constraint layout, the content could exhibit problems 1-3.

    0 讨论(0)
  • 2020-11-22 05:49

    To do this programatically in a fragment you can use following code

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

    Place this in onResume()

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