最近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()のページ上のすべての要素にアタッチします。
公共の静的な無効setupUI(ビュービュー){
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) {}
}
それは、かなり厄介だが、問題は解決しましたが、うまくいけばしかし、より良い方法があります。
scrollViewの内部に置くとどうなりますか?その後、それはまた起こる? –
私はRelativeLayoutをScrollViewの中に入れました:それは何も変わっていません、ごめんなさい –
'EditText'全体が隠されているか、文字がどこから始まっていますか? – codeMagic