EditText默认无法获取焦点,必须点击一次才能获取焦点打开软键盘的解决办法

来源:互联网 发布:法国女人知乎 编辑:程序博客网 时间:2024/05/21 16:59
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);    }

0 0
原创粉丝点击