为什么不使用android:windowSoftInputMode =“" stateVisible | adjustResize"显示软键盘时如何调节屏幕? [英] Why doesn't android:windowSoftInputMode="stateVisible|adjustResize" adjust the screen when soft keyboard is shown?
问题描述
我似乎无法使android:windowSoftInputMode ="stateVisible | adjustResize"选项正常工作. 显示软键盘时,滚动视图不会自动滚动到底部.
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.
编辑:我尝试改用AdjustPan(stateVisible | adjustPan),但发生的情况是禁用了滚动视图.
Edit: I tried using adjustPan instead (stateVisible|adjustPan) but what happens is the scroll view gets disabled.
解决方案:最后,我找到了一条可行的建议.我创建了一个OnGlobalLayoutListener()并将其添加到滚动视图中.我检查了活动根视图(即滚动视图)的高度是否发生了变化.如果是,我假设显示了软键盘.
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.
点击此处以获取更多信息.
这是我的源代码:
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
所需结果
推荐答案
解决方案:最后,我找到了一条可行的建议.我创建了一个OnGlobalLayoutListener()并将其添加到滚动视图中.我检查了活动根视图(即滚动视图)的高度是否发生了变化.如果是,我假设显示了软键盘.
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.
点击此处以获取更多信息.
这篇关于为什么不使用android:windowSoftInputMode =“" stateVisible | adjustResize"显示软键盘时如何调节屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!