3 回答
TA贡献1775条经验 获得超8个赞
public static void hideSoftKeyboard(Activity activity) { InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService( Activity.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow( activity.getCurrentFocus().getWindowToken(), 0);}
hideSoftKeyboard(this)
.
View
instanceof EditText
setOnTouchListener
public void setupUI(View view) { // 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(MyActivity.this); 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); } }}
setContentView
id
id
<RelativeLayoutPanel android:id="@+id/parent"> ... </RelativeLayout>
setupUI(findViewById(R.id.parent))
Activity
setupUI()
onCreate()
<RelativeLayout android:id="@+id/main_parent"> ... </RelativeLayout>
Activity
setupUI(findViewById(R.id.main_parent))
OnResume()
in your program
TA贡献1806条经验 获得超8个赞
OnTouchListener
findViewById(R.id.mainLayout).setOnTouchListener(this)
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);imm.hideSoftInputFromWindow(getCurrentFocus() .getWindowToken(), 0);
- 3 回答
- 0 关注
- 787 浏览
添加回答
举报