5

さて、解決策を探すのに何時間も費やした後、私はここに来ました。

Android側の問題ではないかと思います。

このシンプルなレイアウトを作成してみてください。キーボードを開いて非表示にし、もう一度開くと、EditText が非表示になります。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="300dp"
        android:gravity="center"
        android:inputType="phone"
        android:maxLength="14"
        android:text="some text"
        android:textColor="#666666"
        android:textSize="22sp" />

</RelativeLayout>

今、削除するandroid:gravity="center"と、すべてが機能します! あなたが私に尋ねる前に、ええ、私はすでに追加しましたandroid:windowSoftInputMode="adjustPan"

どんな解決策でも大歓迎です!ありがとう

4

1 に答える 1

2

最近、Nexus 7 スマートフォンでこの問題に対処しました。それ以外の場合、動作は他のテスト電話では発生しませんでした. トリックは、ソフトキーボードを閉じる前にフォーカスを変更することのようです。キーボードは、[完了] ボタンのクリック、編集テキスト ボックスの外側のクリック、[戻る] ボタンの 3 つのポイントで閉じられます。

まず、フォーカスを食い尽くす隠し要素を作成します

 <MyEditText
           android:id="@+id/editHidden"
            android:layout_width="0dp"
             android:layout_height="0dp"
            android:layout_below="@id/imageLogin"
           />

保存してたけどちょっと汚い…

@Override
    protected void onResume() {
        super.onResume();

        Utils.focusable = findViewById(R.id.editHidden);

キーボードが閉じられたら、フォーカスを隠し要素に変更します。

public static void clearFocus() {
        try {
            if (focusable!=null)
                focusable.requestFocus();
        } catch (Exception e) {}
    }

     public static void hideSoftKeyboard(View view) {
        clearFocus();
        if (view!=null) {
            try {
                InputMethodManager inputMethodManager = (InputMethodManager)  view.getContext().getSystemService(Activity.INPUT_METHOD_SERVICE);
                inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
            } catch (Exception e) {}
        }
    }

次に、キーボードが閉じている場所で hideKeyboard 関数を実行します: EditText 戻るボタンが押されました:

@Override
    public boolean onKeyPreIme(int keyCode, KeyEvent event)
    {
       if(keyCode == KeyEvent.KEYCODE_BACK)
       {
           try {
              Utils.clearFocus();
           } catch (Exception e) {}
       }
       return super.onKeyPreIme(keyCode, event);
    }

[完了] ボタンを押して、問題が発生している EditText ボックスにこれを添付します。

public static OnEditorActionListener getOnEditorActionListener() {
        return new OnEditorActionListener() {        

            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if(actionId==EditorInfo.IME_ACTION_DONE){
                     hideSoftKeyboard(v);
                }

                return false;
            }
        };
    }

テキストボックスの外側をクリック - onCreate() でページ上のすべての要素にアタッチします。

public static void setupUI(View ビュー) {

try {
    //Set up touch listener for non-text box views to hide keyboard.
    if(!(view instanceof EditText)) {

        view.setOnTouchListener(new OnTouchListener() {

            public boolean onTouch(View v, MotionEvent event) {
                hideSoftKeyboard(v);
                return false;
            }

        });
    }

    //If a layout container, iterate over children and seed recursion.
    if (view instanceof ViewGroup) {

        for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {

            View innerView = ((ViewGroup) view).getChildAt(i);

            setupUI(innerView);
        }
    }
} catch (Exception e) {}

}

かなり面倒ですが、問題は解決しましたが、もっと良い方法があることを願っています。

于 2013-10-02T08:15:14.080 に答える