2

我們希望在AutoCompleteTextView的活動啓動時顯示鍵盤默認值。 但AutocompletedTextview放置在其中一個片段類中。當fragement開始默認時,我們的鍵盤已顯示。如何在Android中的AutoCompleteTextView的Activity啓動時顯示鍵盤

我們試圖用三種情況:

案例1:

getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); 

案例2:

auto_phone.requestFocus();//auto_phone is AutoCompleteTextView 
     auto_phone.setOnKeyListener(new View.OnKeyListener() { 
      @Override 
      public boolean onKey(View v, int keyCode, KeyEvent event) { 
       if ((event.getAction() == KeyEvent.ACTION_DOWN && (keyCode == KeyEvent.KEYCODE_ENTER))) { 


        return sendChatMessage();//method 
       } 

       return false; 
    } 

案例3:

InputMethodManager imm = (InputMethodManager)getActivity().getSystemService(
       Context.INPUT_METHOD_SERVICE); 
     imm.showSoftInput(auto_phone, 0); 

我們在清單文件中使用也爲作爲鍵盤Visibl的活動e

請指導我們。 高級謝謝!

+0

嘗試使用'imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,InputMethodManager.HIDE_IMPLICIT_ONLY);'的情況下,3 –

回答

0

這對我的作品

public static void showSortKeyboard(View focusedView, Activity activity) { 
    if (focusedView == null) { 
     return; 
    } 
    InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); 
    imm.showSoftInput(focusedView, InputMethodManager.SHOW_IMPLICIT); 
} 
+0

感謝效應初探。 但它不工作......... in oncreteView showSortKeyboard(auto_phone,getActivity()); public static void showSortKeyboard(查看focusedView,Activity活動){ if(focusedView == null){ return; } InputMethodManager imm =(InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(focusedView,InputMethodManager.SHOW_IMPLICIT); } –

+0

我們在onCreate方法中使用了InputManager imgr =(InputMethodManager)getActivity()。getSystemService(Context.INPUT_METHOD_SERVICE); imgr.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT,InputMethodManager.SHOW_FORCED); –

+0

您也可以嘗試 getWindow()。setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); – Andy

相關問題