2015-01-02 53 views
0

我有一個5編輯文本和3個單選按鈕和兩個按鈕的佈局。5編輯文本後,我有3個單選按鈕,然後2個按鈕。在第五編輯文本中輸入文本後,由於軟鍵盤,我無法看到單選按鈕和普通按鈕。輸入第五個編輯文本後,如何禁用該軟鍵盤?任何一個可以請幫我出這個問題...在編輯文本中輸入文字後無法隱藏軟鍵盤

+0

理想情況下,你不應該這樣做,因爲它取決於用戶,以確定他是否正在編輯。所以用戶不應該是關閉鍵盤的人嗎? – Droidekas

回答

0

試試下面的代碼隱藏/關閉軟鍵盤

getWindow().setSoftInputMode(
    WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN 
); 
+0

在上次編輯tetx中輸入文本後,它隱藏了軟鍵盤?我申請了InputMethodManager imm =(InputMethodManager)getSystemService( \t \t Context.INPUT_METHOD_SERVICE); \t \t imm.hideSoftInputFromWindow(country.getWindowToken(),0);代碼爲最後的編輯文本值 – yamuna

0
public void hideKeyBord(View view) { 
    if (view != null) { 
     if (keyBoardHide == null) { 
      keyBoardHide = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 

     } 
     if (keyBoardHide != null && keyBoardHide.isActive()) { 
      // to hide keyboard 
      keyBoardHide.hideSoftInputFromWindow(view.getWindowToken(), 0); 
     } 
    } 
} 
0
 InputMethodManager inputManager = (InputMethodManager) 
       getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); 

     inputManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), 
       InputMethodManager.HIDE_NOT_ALWAYS); 
     getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); 
0

只需使用:

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); 

每當你想隱藏軟鍵盤。

你的情況: 讓你的第五EditTextet .. 然後使用:

if(!et.toString().equals(null)){ 
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
      imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); 
} 


OR

您可以檢測,如果第五EditTextfocused或不是,然後行事科丁(即使用該方法隱藏鍵盤上方如果EditTextfocused)按照以下的鏈接:
How can I detect focused EditText in android?

OR

軟鍵盤上檢測Done鍵事件:
按下DONE按鈕時,鍵盤會自動關閉。但是,如果要執行時,按下按鈕DONE海關措施,請參見下文:

 et= (EditText) findViewById(R.id.edit_text); 

     et.setOnEditorActionListener(new OnEditorActionListener() { 
      @Override 
      public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 
       if (actionId == EditorInfo.IME_ACTION_DONE) { 
        // do your stuff here 
       InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
       imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); 
       } 
       return false; 
      } 

    }); 

希望這有助於!

+0

我會測試第二個你在這裏的位置 – yamuna

+1

當然,讓我知道如果你卡住的地方! –

+0

實際上,在軟鍵盤的某些手機中,有一個按鍵完成所有值輸入 – yamuna

0

隱藏鍵盤不是一個大問題,但你需要確認「什麼時候?」 需要調用

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
        imm.hideSoftInputFromWindow(edittext.getApplicationWindowToken(), 0); 

隱藏softkeyboard

嘗試在你的EditText XML文件中添加android:imeOptions="actionNext"

edittext.setOnEditorActionListener(new TextView.OnEditorActionListener() { 
      @Override 
      public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { 
       boolean flag= false; 
       if (i == EditorInfo.IME_ACTION_NEXT) { 
        flag= true; 
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
        imm.hideSoftInputFromWindow(edittext.getApplicationWindowToken(), 0); 
       } 
       return flag; 
      } 
     }); 

這個代碼會隱藏你的軟鍵盤上點擊旁邊的鍵盤

+0

在所有編輯文本字段填充後不顯示 – yamuna