在onclick事件下.以下方法可行.(如果是EditText失去焦点/得到焦点,没有效果)
显示:
我的用意是点击按钮后显示edittext,而且自动获取焦点并弹出软键盘。
showKeyboard的代码:
这样的话可以每次显示edittext后自动焦点在edittext上。
隐藏:
private void hideKeyboard(){
InputMethodManager im = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
im.hideSoftInputFromWindow(getCurrentFocus().getApplicationWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
显示:
我的用意是点击按钮后显示edittext,而且自动获取焦点并弹出软键盘。
search_layout.setVisibility(View.GONE);
share_top2.setVisibility(View.VISIBLE);
showKeyboard的代码:
private void showKeyboard(){
InputMethodManager im = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
im.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
}
edittext获取焦点:
search_edit.requestFocus();
这样的话可以每次显示edittext后自动焦点在edittext上。