android editext光标隐藏和显示的方法

来源:互联网 发布:广州软件定制 编辑:程序博客网 时间:2024/05/18 13:25
  /*    * 隐藏光标和键盘的方法,传入的parent是editext的付布局    * */    private void cancleForce(RelativeLayout parent,EditText input){        parent.setFocusable(true);        parent.setFocusableInTouchMode(true);        try{            if(input.getText()==null||input.getText().equals("")){            }else {                input.setText("");            }            ((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(MainActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);        }catch (Exception e){}    }    /*    * 获取光标的方法    * */    public void getForce(EditText input){        input.setFocusable(true);        input.setText("");        input.setFocusableInTouchMode(true);        input.requestFocus();    }

0 0