在文本选择上禁用键盘

时间:2013-08-05 07:38:57

标签: android android-edittext selection

我的应用程序使用Android的默认键盘和自定义键盘。我已经设置过,无论何时调用默认键盘,我的自定义键盘都会关闭,反之亦然。我的问题是,在某些设备(如Galaxy S3)上,无论何时选择文本,默认键盘都会显示为与我的自定义键盘重叠。 有没有办法处理或修改用于在edittext上选择/突出显示文本的事件?

2 个答案:

答案 0 :(得分:0)

  

试试这个我的作品

Keypad.this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

答案 1 :(得分:0)

 InputMethodManager inputMethodManager = (InputMethodManager)  activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
    inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);

使用event ::

@Override
public boolean dispatchTouchEvent(MotionEvent event) {
    View view = getCurrentFocus();
    boolean ret = super.dispatchTouchEvent(event);

    if (view instanceof EditText) {
        View w = getCurrentFocus();
        int scrcoords[] = new int[2];
        w.getLocationOnScreen(scrcoords);
        float x = event.getRawX() + w.getLeft() - scrcoords[0];
        float y = event.getRawY() + w.getTop() - scrcoords[1];

        if (event.getAction() == MotionEvent.ACTION_UP 
 && (x < w.getLeft() || x >= w.getRight() 
 || y < w.getTop() || y > w.getBottom()) ) { 
            InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(getWindow().getCurrentFocus().getWindowToken(), 0);
        }
    }
 return ret;
}