3

所以我有一个正在使用的活动,windowSoftInputMode="adjustPan"我有一个OnPreDrawListener调用EditText

editText.requestFocus();
inputManager.showSoftInput(editText, 0);

哪个按预期工作并推动Activity向上为EditText. 但是,如果我使用后退按钮关闭键盘(将窗口平移回原始位置),然后EditText再次触摸以显示键盘,键盘显示,但窗口不调整。

我什至尝试OnClickListener在 the 中添加一个EditText并再次调用相同的两个调用:

editText.requestFocus();
inputManager.showSoftInput(editText, 0);

但是在我关闭窗口并再次显示之前,窗口不会平移。有什么建议么?

4

2 回答 2

0

I think this three steps will solve your problem.

1)in manifest file change windowSoftInputMode="adjustPan" to windowSoftInputMode="adjustResize"

2) The layout you are using for EditText , tha change the parent layout to ScroolView.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/android:list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    <EditText
        android:id="@+id/edittextview"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:inputType="textFilter"
        android:padding="10dp"
        android:imeOptions="actionDone"
        android:scrollbars="vertical"
        android:textSize="14sp" />
</ScrollView>

3) To explicitly showing keyboard to avoid "dismiss the keyboard with the back button and window is not Adjust" in Edittext onclick write

edittext.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                InputMethodManager m = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                if (m != null) {
                    m.toggleSoftInput(0, InputMethodManager.SHOW_IMPLICIT);
                    edittext.requestFocus();
                }
            }
        });

Hope this will solve your problem.

于 2013-03-08T03:55:57.017 回答
0

因此,这并不是问题的完全解决方案,而是我最终采用的解决方法。我创建了一个子类LinearLayout来在 IME 接收到它之前拦截后退按钮按下:

public class IMEInterceptLinearLayout extends LinearLayout {
    //For some reason, the event seems to occur twice for every back press
    //so track state to avoid firing multiple times
    private boolean notifiedListener = false;
    private OnBackPressedPreIMEListener listener;

    public IMEInterceptLinearLayout(Context context) {
        super(context);
    }

    public IMEInterceptLinearLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public IMEInterceptLinearLayout(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public void setOnBackPressedPreIMEListener(OnBackPressedPreIMEListener listener) {
        this.listener = listener;
    }

    private void fireOnBackPressedPreIME() {
        if(listener != null && !notifiedListener) {
            listener.onBackPressedPreIME();
            notifiedListener = true;
        }
    }

    @Override
    public boolean dispatchKeyEventPreIme(KeyEvent event) {
        if(event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
            fireOnBackPressedPreIME();
            return true;
        } else return super.dispatchKeyEventPreIme(event);
    }

    public interface OnBackPressedPreIMEListener {
        public void onBackPressedPreIME();
    }
}

然后从那里我刚刚将我的窗口注册为布局的侦听器,并在我收到事件时关闭窗口和键盘,不允许在窗口可见时关闭键盘。

于 2013-03-12T08:15:52.493 回答