private EditText inputView;inputView = (EditText) findViewById(R.id.inputView);//获取焦点防止点击一次才能打开软键盘
inputView.setFocusable(true);inputView.setFocusableInTouchMode(true);inputView.requestFocus();showSoftInput(inputView);
/** * 隐藏软键盘输入法 * * @param v */ private void hideSoftInput(View v) { ((TextView)v).setText(""); // if(TextUtils.isEmpty(writeComment.getText())){//清空写回复信息,准备评论楼主 // pid=""; // writeComment.setHint(getResources().getString(R.string.hint_write_comment)); // } InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(v.getWindowToken(), 0); } /** * 显示软键盘输入法 * * @param v */ private void showSoftInput(View v) { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(v, InputMethodManager.SHOW_FORCED); }