0

Android 용 사용자 정의 키보드를 설계하고 있습니다. 내 응용 프로그램의 일부 필드에 대해 Enter 키에 대한 사용자 지정 레이블을 갖고 싶습니다. 필자는 키보드 개발을 위해 샘플 SoftKeyboard 프로젝트를 사용했습니다. 지금까지 시도 무엇 : 내 활동 중 하나에서 1 나는 다음과 같은 속성을 가진 글고이 : 나는 네이티브 안드로이드 키보드를 사용하는 경우Android에서 사용자 정의 키보드의 Enter 키 레이블을 변경할 수 없습니다.

<EditText 
    android:id="@+id/password" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 

    android:imeActionId="@+id/action_sign_in" 
    android:imeActionLabel="@string/sign_in" 

    android:inputType="textPassword" /> 

는 내 입력 키를하지만, 경우 "로그인"이 표시 I

void setImeOptions(Resources res, int options) 
    { 
     if (mEnterKey == null) 
     { 
      return; 
     } 

     switch (options & (EditorInfo.IME_MASK_ACTION | EditorInfo.IME_FLAG_NO_ENTER_ACTION)) 
     { 
      case EditorInfo.IME_ACTION_GO: 
       mEnterKey.iconPreview = null; 
       mEnterKey.icon = null; 
       mEnterKey.label = res.getText(R.string.label_send_key); 
       break; 
      case EditorInfo.IME_ACTION_NEXT: 
       mEnterKey.iconPreview = null; 
       mEnterKey.icon = null; 
       mEnterKey.label = res.getText(R.string.label_next_key); 
       break; 
      case EditorInfo.IME_ACTION_SEARCH: 
       mEnterKey.icon = res.getDrawable(R.drawable.sym_keyboard_search); 
       mEnterKey.label = null; 
       break; 
      case EditorInfo.IME_ACTION_SEND: 
       mEnterKey.iconPreview = null; 
       mEnterKey.icon = null; 
       mEnterKey.label = res.getText(R.string.label_send_key); 
       break; 
      case R.id.action_sign_in: 
       mEnterKey.iconPreview = null; 
       mEnterKey.icon = null; 
       mEnterKey.label = res.getText(R.string.sign_in); 
       break; 
      default: 
       mEnterKey.label = res.getText(R.string.label_send_key); 
       mEnterKey.icon = null; 
       break; 
     } 

    } 
} 

LatinKeyboard.java에서 누군가가 나이 문제를 해결하는 데 도움이 될 수 있다면 감사하겠습니다 : 그것은 다음 문에 키를 입력의 기본 값을 보여줍니다 내 사용자 정의 키보드를 사용합니다.

답변

2

마지막으로 해결책을 찾았습니다. int 옵션을 전달하는 대신 EditorInfo 특성을 전달해야합니다.

void setImeOptions(Resources res, EditorInfo ei) 
    { 
     if (enterKey == null) 
     { 
      return; 
     } 

     switch (ei.imeOptions & (EditorInfo.IME_MASK_ACTION | EditorInfo.IME_FLAG_NO_ENTER_ACTION)) 
     { 
      case EditorInfo.IME_ACTION_SEND: 
       enterKey.iconPreview = null; 
       enterKey.icon = null; 
       enterKey.label ="Send"; 
       break; 
      case EditorInfo.IME_ACTION_GO: 
       enterKey.iconPreview = null; 
       enterKey.icon = null; 
       enterKey.label ="Go"; 
       break; 
      case EditorInfo.IME_ACTION_NEXT: 
       enterKey.iconPreview = null; 
       enterKey.icon = null; 
       enterKey.label = "Next"; 
       break; 
      case EditorInfo.IME_ACTION_SEARCH: 
       enterKey.icon = res.getDrawable(R.drawable.sym_keyboard_search); 
       enterKey.label = null; 
       break; 
      default: 
       enterKey.iconPreview = null; 
       enterKey.label = "Enter"; 
       enterKey.icon = null; 
       break; 
     } 

     if (ei.actionLabel != null) 
     { 
      enterKey.iconPreview = null; 
      enterKey.icon = null; 
      enterKey.label = ei.actionLabel; 
     } 
    } 
: 우리는

@Override 
    public void onStartInput(EditorInfo attribute, boolean restarting) 
    { 
     super.onStartInput(attribute, restarting); 
     ... 
     yourSoftKeyboard.setImeOptions(getResources(), attribute); 
} 

그런 다음 우리가 울부 짖는 소리와 같은 setImeOptions을 구현 노호처럼 통과