我在使用安卓棒棒糖时遇到了一个问题,软键盘弹出后屏幕大小没有自动调整。
以下是我制作的其中一个活动的清单介绍示例:
android:windowSoftInputMode="stateAlwaysHidden|adjustResize"
是否有新的内容需要添加并考虑到Android 5.0?ScrollView在Android < 5.0上工作正常。
我在使用安卓棒棒糖时遇到了一个问题,软键盘弹出后屏幕大小没有自动调整。
以下是我制作的其中一个活动的清单介绍示例:
android:windowSoftInputMode="stateAlwaysHidden|adjustResize"
是否有新的内容需要添加并考虑到Android 5.0?ScrollView在Android < 5.0上工作正常。
对于那些即使在ScrollView中已经设置了android:fitsSystemWindows="true"
仍然存在此问题的人们,我找到了几种解决方法:
fragment.xml
的RelativeLayout,并在其中添加android:fitsSystemWindows="true"
。将ScrollView作为RelativeLayout的子级。<RelativeLayout android:fitsSystemWindows="true">
<ScrollView/>
</RelativeLayout>
这两个选项都应该与android:windowSoftInputMode="adjustResize"
一起使用,并且在Android 5上使用<item name="android:windowTranslucentStatus">true</item>
标记。
android:fitsSystemWindows="true"
我尝试过的所有方法都没有奏效,我已经尝试了每种可能的不同清单设置组合,但都无济于事。
这个方法有点hacky,但对我来说非常有效:
((RelativeLayout) findViewById(R.id.rootLayout)).addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
scrollToLatest(); // Do your scrolling!
}
});