2014-01-29 71 views
0

我是android開發新手。我在EditText中使用android:imeOptions = "actionDone|flagNoExtractUi",我在軟鍵盤上將「完成」文本更改爲「登錄」。點擊登錄Button軟鍵盤時我如何執行某些操作?Android:在鍵盤按鈕上執行操作

回答

0

例如創建方法,

public void OnClickButton(View v) 
{ 
/* 
. 
. 
. 
*/ 
} 

現在,在您layout.xml文件你的按鈕標記添加

android:onclick="OnClickButton" 

,在這裏你去...

0

找到答案您對此鏈接的問題:

Asha response

但是請記住說什麼CommonsWare在最佳答案!

0

試試這個代碼...

ed.setSingleLine(true); 
     ed.setHint("search places"); 
     ed.setTextSize(16); 
     ed.setImeActionLabel("NAME YOU WANT TO GIVE FOR DISPLAY", EditorInfo.IME_FLAG_NAVIGATE_NEXT); 
     ed.setImeOptions(EditorInfo.IME_FLAG_NO_FULLSCREEN); 
     ed.setOnEditorActionListener(new EditText.OnEditorActionListener() { 
      @Override 
      public boolean onEditorAction(TextView v, int actionId, 
        KeyEvent event) { 

       if (event != null && event.getAction() != KeyEvent.ACTION_DOWN) { 
         return false; 
        } 
       else if (actionId == EditorInfo.IME_ACTION_SEARCH 
         || actionId == EditorInfo.IME_ACTION_DONE|| event == null 
         || event.getAction() == KeyEvent.ACTION_DOWN 
         && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) { 

        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); 
        imm.hideSoftInputFromWindow(
          ed.getWindowToken(), 0); 





        //DO YOUR WORK HERE ..... 




        return true; 
       } 
       return false; 
      } 
     });