adjustPan not preventing keyboard from covering EditText

被刻印的时光 ゝ 提交于 2019-11-26 12:23:26

After doing a lot of searching apparently it's what I'm calling a bug. If you use the fullscreen tag (to remove the status bar from the activity) you can't use "adjustResize" without wrapping the activity in a ScrollView. Unfortunately for me I'm using a ListView which would create yet another problem. I'm sick of messing with it and will probably just abandon the fullscreen on that activity.

LocalPCGuy

In your manifest file, you need to set the appropriate android:windowSoftInputMode property. This attribute is valid since API 3.

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

Options are: http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft

  • stateUnspecified The state of the soft keyboard (whether it is hidden or visible) is not specified. The system will choose an appropriate state or rely on the setting in the theme. This is the default setting for the behavior of the soft keyboard.
  • stateUnchanged The soft keyboard is kept in whatever state it was last in, whether visible or hidden, when the activity comes to the fore.
  • "stateHidden" The soft keyboard is hidden when the user chooses the activity — that is, when the user affirmatively navigates forward to the activity, rather than backs into it because of leaving another activity.
  • stateAlwaysHidden The soft keyboard is always hidden when the activity's main window has input focus.
  • stateVisible The soft keyboard is visible when that's normally appropriate (when the user is navigating forward to the activity's main window).
  • stateAlwaysVisible The soft keyboard is made visible when the user chooses the activity — that is, when the user affirmatively navigates forward to the activity, rather than backs into it because of leaving another activity.
  • adjustUnspecified It is unspecified whether the activity's main window resizes to make room for the soft keyboard, or whether the contents of the window pan to make the current focus visible on-screen. The system will automatically select one of these modes depending on whether the content of the window has any layout views that can scroll their contents. If there is such a view, the window will be resized, on the assumption that scrolling can make all of the window's contents visible within a smaller area. This is the default setting for the behavior of the main window.
  • adjustResize The activity's main window is always resized to make room for the soft keyboard on screen.
  • adjustPan The activity's main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window.

if you set android:windowSoftInputMode="adjustResize" for an activity in the manifest, then a ScrollView (or other collapsable ViewGroups) will shrink to accommodate the soft keyboard. But, if you set android:windowFullscreen="true" in the activity’s theme, then the ScrollView won’t shrink because it’s forced to fill the whole screen. However, setting android:fitsSystemWindows="false" in your theme also causes adjustResize not to work

I had this in my AndroidManifest. It caused the adjustPan to stop working correctly. I removed the block below and everything works fine again.

<supports-screens
        android:smallScreens="true"
        android:normalScreens="true"
        android:largeScreens="true"
        android:xlargeScreens="false"
        android:anyDensity="false" />

Here is one workaround I have found. Open the problematic editText and hit the RETURN key. Notice it shifts the editText closer to the position you're shooting for.

So although hacky, you can essentially please a newline at the top of the edittext.

This also seems to work using a newline at the bottom but you'd have to use a delay to not add the newline until AFTER the soft keyboard has animated into position.

Note I only have this problem on certain phones (DroidX).

if (android.os.Build.MODEL.equals("DROIDX")) {
        inputEt.setOnFocusChangeListener(new OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                    String text = inputEt.getText().toString();
                    text = "\n\n" + text.trim();
                    inputEt.setText(text);  
                    inputEt.setSelection(text.length());
                }
            });
        }
user3030130

Try adding android:windowSoftInputMode="adjustResize|stateVisible|stateAlwaysHidden" in your manifest.

You can try the following settings:

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