Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/182.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何防止显示软键盘后弹出窗口位移?_Android_Android Softkeyboard - Fatal编程技术网

Android 如何防止显示软键盘后弹出窗口位移?

Android 如何防止显示软键盘后弹出窗口位移?,android,android-softkeyboard,Android,Android Softkeyboard,我创建了带有编辑文本的WindowPopup。当我专注于它时,软键盘会显示并将弹出窗口移到上限上方,所以我看不到我正在键入的内容。我想显示键盘,而不移动视图,就在视图上方。 我读到我可以为它更改softInputMode,所以我创建了一个从EditText扩展而来的类,并尝试在onFocusListener中更改inputMode,但没有帮助 setOnFocusChangeListener(new OnFocusChangeListener() { @Override pub

我创建了带有编辑文本的WindowPopup。当我专注于它时,软键盘会显示并将弹出窗口移到上限上方,所以我看不到我正在键入的内容。我想显示键盘,而不移动视图,就在视图上方。 我读到我可以为它更改softInputMode,所以我创建了一个从EditText扩展而来的类,并尝试在onFocusListener中更改inputMode,但没有帮助

setOnFocusChangeListener(new OnFocusChangeListener() {

    @Override
    public void onFocusChange(View veiw, boolean has_focus) {

        if (has_focus) {
            //Try to change input mode to prevent displacing
            ((Activity) getContext()).getWindow().setSoftInputMode(
            WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
        } else {
            //.. return back previous input mode
        }

});
我这样做了,因为我只需要在这个弹出窗口中使用这种行为,但我甚至尝试更改我的manifets文件中的action属性

android:windowSoftInputMode="adjustNothing"

我可以在不移动视图的情况下显示键盘吗


另外,我正在使用Android API 15

当PopupWindow创建弹出视图时,它会将新的WindowManager.LayoutParams设置为softInputMode,这会覆盖Window.softInputMode的行为。这里是来自PopupWindow的一段代码

private WindowManager.LayoutParams createPopupLayout(IBinder token) {

    WindowManager.LayoutParams p = new WindowManager.LayoutParams();
    p.gravity = Gravity.LEFT | Gravity.TOP;
    p.width = mLastWidth = mWidth;
    p.height = mLastHeight = mHeight;
    if (mBackground != null) {
        p.format = mBackground.getOpacity();
    } else {
        p.format = PixelFormat.TRANSLUCENT;
    }
    p.flags = computeFlags(p.flags);
    p.type = mWindowLayoutType;
    p.token = token;
    /*mSoftInputMode is the private field which is by default equals
      to WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED 
    */
    p.softInputMode = mSoftInputMode;
}
setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
所以要更改softInputMode,只需调用PopupWindow的public方法

private WindowManager.LayoutParams createPopupLayout(IBinder token) {

    WindowManager.LayoutParams p = new WindowManager.LayoutParams();
    p.gravity = Gravity.LEFT | Gravity.TOP;
    p.width = mLastWidth = mWidth;
    p.height = mLastHeight = mHeight;
    if (mBackground != null) {
        p.format = mBackground.getOpacity();
    } else {
        p.format = PixelFormat.TRANSLUCENT;
    }
    p.flags = computeFlags(p.flags);
    p.type = mWindowLayoutType;
    p.token = token;
    /*mSoftInputMode is the private field which is by default equals
      to WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED 
    */
    p.softInputMode = mSoftInputMode;
}
setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
而且不需要记住以前的软输入法,因为这种行为只适用于此PopupWindow

private WindowManager.LayoutParams createPopupLayout(IBinder token) {

    WindowManager.LayoutParams p = new WindowManager.LayoutParams();
    p.gravity = Gravity.LEFT | Gravity.TOP;
    p.width = mLastWidth = mWidth;
    p.height = mLastHeight = mHeight;
    if (mBackground != null) {
        p.format = mBackground.getOpacity();
    } else {
        p.format = PixelFormat.TRANSLUCENT;
    }
    p.flags = computeFlags(p.flags);
    p.type = mWindowLayoutType;
    p.token = token;
    /*mSoftInputMode is the private field which is by default equals
      to WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED 
    */
    p.softInputMode = mSoftInputMode;
}
setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);