Why doesn't android:windowSoftInputMode=“stateVisible|adjustResize” adjust the screen when soft keyboard is shown?

混江龙づ霸主 提交于 2019-12-18 17:04:36

问题


I can't seem to make the android:windowSoftInputMode="stateVisible|adjustResize" option work. When the soft keyboard shows, the scroll view doesn't automatically scroll to the bottom part.

Edit: I tried using adjustPan instead (stateVisible|adjustPan) but what happens is the scroll view gets disabled.

Solution: Finally, I found a suggestion that works. I created an OnGlobalLayoutListener() and added it to my scroll view. I checked if the height of the root view of my activity(which is my scroll view) changed. If yes, I'm assuming that the soft keyboard is shown.

Click here for more info.

Here's my source code:

AndroidManifest.xml

<application
        ...
        android:theme="@android:style/Theme.NoTitleBar" >
        <activity
            ...
            android:screenOrientation="portrait"
            android:windowSoftInputMode="stateVisible|adjustResize" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        ...
</application>

Login Screen with keyboard - scroll view does not scroll

Desired result


回答1:


Solution: Finally, I found a suggestion that works. I created an OnGlobalLayoutListener() and added it to my scroll view. I checked if the height of the root view of my activity(which is my scroll view) changed. If yes, I'm assuming that the soft keyboard is shown.

Click here for more info.




回答2:


try

android:windowSoftInputMode="adjustPan|stateVisible"



回答3:


You could automatically scroll to the bottom of your activity by yourself, by overriding the onConfigurationChanged() callback in you Activity :

scrollView.post(new Runnable() {            
    @Override
    public void run() {
           scrollView.fullScroll(View.FOCUS_DOWN);              
    }
});

This means you also have to tell your activity you want the callback to be called when the activity changes its layout by using the configChanges attribute in the activity declaration in your AndroidManifest file :

<activity
    android:configChanges="screenLayout|screenSize" <!-- Don't know which could actually do the trick -->
    ... >
</activity>

I hope this can help you.




回答4:


In Manifest:

android:windowSoftInputMode="adjustPan|stateVisible"

In layout xml bottom of all child layout of scrollview set one textview, such as

  <ScrollView
    android:id="@+id/driverLoginScrollView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fillViewport="false"
    android:scrollbars="none">
     <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="50dp"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:orientation="vertical">
        .
        .
        .
       <TextView
       android:layout_width="match_parent"
       android:layout_height="100dp"
       android:focusable="false"
       android:textIsSelectable="false" />
       </LinearLayout>
</ScrollView>



回答5:


I found that if I had set layout parameters on my scroll view, then it would not work. As soon as a removed the layout parameters it worked as expected. I can't explain why, just letting others know what worked for me.



来源:https://stackoverflow.com/questions/22141168/why-doesnt-androidwindowsoftinputmode-statevisibleadjustresize-adjust-the-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!