13
사용자가 소프트 키보드에서 "완료"를 누르면 키보드가 닫힙니다. 특정 조건 (예 : 암호가 올바르게 입력 된 경우) 만 닫히기를 원합니다. 나는 그것이 전에이 코드 를 실행하기 때문에이 작동하지 않는 이유는 아마도 실현키보드에서 완료를 누를 때 키보드를 닫지 않는 방법
final EditText et = (EditText)findViewById(R.id.et);
et.setOnEditorActionListener(new OnEditorActionListener()
{
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
{
if(actionId==EditorInfo.IME_ACTION_DONE)
{
if (et.getText().toString().equals(password)) // they entered correct
{
// log them in
}
else
{
// bring up the keyboard
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
Toast.makeText(Main.this, "Incorrect.", Toast.LENGTH_SHORT).show();
}
}
return false;
}
});
:
이
내 코드 (이하 "완료"버튼을 누를 때의 리스너를 설정)입니다 실제로 소프트 키보드를 자체적으로 닫습니다. 그러나 이것이 도움이 필요한 이유입니다. 나는 다른 방법을 모른다. 답변 이가능한 주제로 작업 할 수 있습니다 :
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
과 그런 종류의 물건,하지만 난 확실히 모른다.
해결책 :
EditText et = (EditText)findViewById(R.id.et);
et.setOnEditorActionListener(new OnEditorActionListener()
{
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
{
if(actionId==EditorInfo.IME_ACTION_DONE)
{
if (et.getText().toString().equals(password)) // they entered correct
{
// log them in
return false; // close the keyboard
}
else
{
Toast.makeText(Main.this, "Incorrect.", Toast.LENGTH_SHORT).show();
return true; // keep the keyboard up
}
}
// if you don't have the return statements in the if structure above, you
// could put return true; here to always keep the keyboard up when the "DONE"
// action is pressed. But with the return statements above, it doesn't matter
return false; // or return true
}
});
위대한 답변입니다. 메서드가 반환해야하는 내용에 대한 설명서를 찾을 수 없습니다. –