Android는 온 스크린 키보드의 완료 키 누름을 감지합니다.


답변:


276

예, 가능합니다 :

editText = (EditText) findViewById(R.id.edit_text);

editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_DONE) {
            // do your stuff here
        }
        return false;
    }
});

다음 라이브러리를 가져와야합니다.

import android.view.KeyEvent;
import android.view.inputmethod.EditorInfo;
import android.widget.TextView;

감사합니다. 좋은 출발점을 주셨습니다. EditorInfo.IME_ACTION_SEARCH대신 렌즈 검색 버튼 을 사용해야 했습니다.
TechNyquist

? 안녕하세요, ButterKnife @ mikeyaworski @ SzabolcsBerecz으로이 가능
Maulik Dodia

1
@MaulikDodia 버터 나이프의 @OnEditorAction ()을 사용할 수 있습니다
Ridcully

감사합니다. I will with it @ Ridcully
Maulik Dodia

3

편집기 정보는 Android 애플리케이션에서 모든 유형의 사용자 입력을 처리해야 할 때 가장 유용한 클래스입니다. 예를 들어 로그인 / 등록 / 검색 작업에서보다 정확한 키보드 입력을 위해 사용할 수 있습니다. 편집기 정보 클래스는 입력 방법이 편집 텍스트 내용과 직접 통신 할 텍스트 편집 개체에 대한 여러 속성을 설명합니다.

IME_ACTION_DONE으로 시도 할 수 있습니다 .

이 작업은 Done입력 할 항목 이없는 작업을 수행하고이 IME닫힙니다.

setOnEditorActionListener 사용

EditTextObj.setOnEditorActionListener(new TextView.OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        boolean handled = false;
        if (actionId == EditorInfo.IME_ACTION_DONE) {
            /* Write your logic here that will be executed when user taps next button */
            handled = true;
        }
        return handled;
    }
});

사용자 정의 키보드로 동일한 문제를 처리하는 방법은 무엇입니까?
Gaju Kollur 2017

0

버터 나이프를 사용하면

@OnEditorAction(R.id.signInPasswordText)
boolean onEditorAction(TextView v, int actionId, KeyEvent event){
    if (actionId == EditorInfo.IME_ACTION_DONE || event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
        /* Write your logic here that will be executed when user taps next button */
    }
    return false;
}
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.