2013-07-04 33 views
4

我設置軟Android鍵盤上的OK鍵,當我在下面顯示的EditText上點擊:控制好SoftKeyboard按鈕的Android

<EditText 
      android:id="@+id/rlMP3SeekContainer" 
      android:layout_width="0dp" 
      android:layout_height="40dp" 
      android:layout_weight="1" 
      android:background="@drawable/text_rougea" 
      android:singleLine="true" 
      android:imeOptions="actionDone" 
      android:ems="10" 
      android:hint="@string/hint_deezer_search" 
      android:paddingLeft="@dimen/eight_dp" 
      android:paddingRight="@dimen/eight_dp" 
      android:textColor="@color/black" 
      android:textColorHint="@color/gray_text" 
      android:textSize="@dimen/twelve_sp" /> 

當鍵盤出現我希望用戶上的OK按鈕點擊做一些事情的時候。但我怎麼能覆蓋鍵盤上的OK按鈕做我想做的事情

回答

14

您需要實現OnEditorActionListener:

yourEditText.setOnEditorActionListener(
     new EditText.OnEditorActionListener() { 
    @Override 
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 
      if (actionId == EditorInfo.IME_ACTION_DONE) { 
      /* your code here */ 
      } 
    } 
}); 
+0

是由於Thommy – Dimitri