话不多说,直接上解决方法。
在AndroidManifest.xml

activity 里面加上android:windowSoftInputMode=“adjustPan|stateHidden”

<activity android:name=".SelectMoShiActivity"  android:windowSoftInputMode="adjustPan|stateHidden"/>

完美解决。

原理如下(不要看,浪费时间)
在Android官方文档中如下定义setSoftInputMode(int mode)方法:

    /**
     * Specify an explicit soft input mode to use for the window, as per
     * {@link WindowManager.LayoutParams#softInputMode
     * WindowManager.LayoutParams.softInputMode}.  Providing anything besides
     * "unspecified" here will override the input mode the window would
     * normally retrieve from its theme.
     */
    public void setSoftInputMode(int mode) {
        final WindowManager.LayoutParams attrs = getAttributes();
        if (mode != WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED) {
            attrs.softInputMode = mode;
            mHasSoftInputMode = true;
        } else {
            mHasSoftInputMode = false;
        }
        dispatchWindowAttributesChanged(attrs);
    }

其他常用的软键盘输入法模式还包括:

//软键盘的状态并没有指定,系统将选择一个合适的状态或依赖于主题的设置
public static final int SOFT_INPUT_STATE_UNSPECIFIED = 0;

//当这个activity出现时,软键盘将一直保持在上一个activity里的状态,无论是隐藏还是显示
public static final int SOFT_INPUT_STATE_UNCHANGED = 1;

//用户选择activity时,软键盘总是被隐藏
public static final int SOFT_INPUT_STATE_HIDDEN = 2;

//当该Activity主窗口获取焦点时,软键盘也总是被隐藏的
public static final int SOFT_INPUT_STATE_ALWAYS_HIDDEN = 3;

//软键盘通常是可见的
public static final int SOFT_INPUT_STATE_VISIBLE = 4;

//用户选择activity时,软键盘总是显示的状态
public static final int SOFT_INPUT_STATE_ALWAYS_VISIBLE = 5;

//默认设置,通常由系统自行决定是隐藏还是显示
public static final int SOFT_INPUT_ADJUST_UNSPECIFIED = 0x00;

//该Activity总是调整屏幕的大小以便留出软键盘的空间
public static final int SOFT_INPUT_ADJUST_RESIZE = 0x10;

//当前窗口的内容将自动移动以便当前焦点从不被键盘覆盖和用户能总是看到输入内容的部分
public static final int SOFT_INPUT_ADJUST_PAN = 0x20;

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐