0

我用edittext创建了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
        }

});

我这样做了,因为我只在这个弹出窗口中需要这种行为,但我什至尝试在我的清单文件中更改操作属性

android:windowSoftInputMode="adjustNothing"

或者

android:windowSoftInputMode="stateHidden"

我可以在不改变视图的情况下显示键盘吗?

PS我正在使用Android API 15

4

1 回答 1

2

当 PopupWindow 创建弹出视图时,它会使用 softInputMode 为其设置新的 WindowManager.LayoutParams,这会覆盖 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;
}

所以要改变 softInputMode 你只需要调用 PopupWindow 的公共方法

setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);

并且不需要记住之前的软输入法,因为这种行为只会针对这个PopupWindow

于 2013-07-31T13:03:01.587 回答