2011-01-09 3 views
2

편집 가능한 바깥 쪽을 클릭하면 안드로이드에있는 텍스트 상자와 같이 키보드를 (코드별로) 사라지게 할 수 있습니까?안드로이드에서 텍스트 상자 바깥을 클릭하면 어떻게 키보드가 사라지나요?

+1

iOS 기기에서 키보드가 부착 된보기를 클릭하면 화면이 사라집니다. Android에서는 그렇지 않습니다. 표준 동작에 따르면 뒤로 버튼을 만지면 남성이 키보드 숨기기를합니다. –

+0

이 링크 확인 http://stackoverflow.com/questions/4165414/how-to-hide-soft-keyboard-on-android-after-clicking-outside-edittext – GSree

답변

0
public boolean OutsideTouchEvent(MotionEvent m_event) { 
    View v = getCurrentFocus(); 
    boolean value = super.dispatchTouchEvent(m_event); 
    View w = getCurrentFocus(); 
    int scrcoords[] = new int[2]; 
    w.getLocationOnScreen(scrcoords); 
    float x = m_event.getRawX() + w.getLeft() - scrcoords[0]; 
    float y = m_event.getRawY() + w.getTop() - scrcoords[1]; 

    if (m_event.getAction() == MotionEvent.ACTION_UP && (x < w.getLeft() || x >= w.getRight() || y < w.getTop() || y > w.getBottom())) { 
     InputMethodManager inputMethodManager = (InputMethodManager) YourActivity.this.getSystemService(Activity.INPUT_METHOD_SERVICE); 
     inputMethodManager.hideSoftInputFromWindow(YourActivity.this.getCurrentFocus().getWindowToken(), 0); 
    } 
    return value; 

} 
관련 문제