私はあなたが私のシナリオとそれを比較することができますし、あなたの上に適用することができ、同じシナリオを解決した。
私のシナリオ:任意の場所のEditTextを受け入れ、画面のタッチのキーボードを非表示にします。
解決方法:キーボードを非表示にするには、テキストボックス以外の表示用にタッチリスナーを設定してください。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
setupUI(findViewById(R.id.scrolview)); // === scrolview is container of all views inside it ===
}
public void setupUI(View view) {
//Set up touch listener for non-text box views to hide keyboard.
if(!(view instanceof EditText)) {
view.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
hideSoftKeyboard(SignupActivity.this);
findViewById(R.id.first_linear_layout).requestFocus();
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);
}
}
}
public static void hideSoftKeyboard(Activity activity) {
InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
}
普遍的なありません "どこかでなく、そこに" このようなリスナーのためのスポット。子供がそれらを消費しない場合、タッチイベントが親に渡されるので、トップレベルコンテナに 'OnClickListener'を追加してください。 – CommonsWare