2016-12-14 136 views
1

我目前正在制作一个我自己的软键盘在android中,并很难得到选择的ime动作 - (IME_ACTION_SEARCHIME_ACTION_DONEIME_ACTION_DONE等)。android自定义软键盘拦截ime_action

例如,如果用户输入谷歌搜索的动作按钮应该是一个搜索按钮,如果它是一个短信,那么它将是一个换行符。我如何区分它们?

我试过在没有运气的情况下找它。

onCreateInputView(){} 

任何帮助表示赞赏。

回答

1

您可致电getCurrentInputEditorInfo在您的InputMethodService。然后你可以检查EditorInfo的imeOptions property

int imeOptions = mInputMethodService.getCurrentInputEditorInfo().imeOptions; 
switch (imeOptions&EditorInfo.IME_MASK_ACTION) { 
      case EditorInfo.IME_ACTION_NONE: 
       // None 
      case EditorInfo.IME_ACTION_GO: 
       // Go 
      case EditorInfo.IME_ACTION_SEARCH: 
       // Serach 
      case EditorInfo.IME_ACTION_SEND: 
       // Send 
      case EditorInfo.IME_ACTION_NEXT: 
       // Next 
      case EditorInfo.IME_ACTION_DONE: 
       // Done 
     } 
+0

我有同样的问题。但getCurrentInputEditorInfo()。抛出null? –