2013-10-20 50 views
0

我無法使editText上的鍵盤動態顯示。Android無法使用鍵盤顯示InputMethodManager

  //should show the Keyboard 
     editText.setFocusableInTouchMode(true); 
     editText.requestFocus(); 

     final InputMethodManager mgr = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 
     mgr.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT); 



      //or this also does not work 
     mgr.toggleSoftInputFromWindow(editText.getWindowToken(),InputMethodManager.SHOW_FORCED ,InputMethodManager.HIDE_IMPLICIT_ONLY); 

下面是EditText上的XML的代碼:

 <EditText 
      android:id="@+id/searchHeaderView" 
      android:textSize="13dip" 
      android:layout_marginLeft="10dip" 
      android:layout_marginRight="10dip" 
      android:layout_width="fill_parent" 
      android:layout_height="0dp" 
      android:padding="5dip" 
      android:background="#00000000" 
      android:hint="@string/searchViewHint" 

      /> 

在相同的應用程序在它與另一的EditText另一個活動。

+0

我希望你正在取得進展。如果我的答案對您有幫助,請將其投票或標記爲正確。這有助於您獲得聲譽,並幫助他人更輕鬆地找到有用的答案。 –

回答

0

這裏有幾件事情要嘗試:

一,確保EDITTEXT實際上是越來越關注的焦點。添加一個OnFocusChangeListener,然後在偵聽器中放置一個斷點或生成一些跟蹤輸出。

二,在請求焦點和顯示鍵盤之間放了一段時間。像這樣:

post (new Runnable() 
{ 
    @Override 
    public void run() 
    { 
    final InputMethodManager mgr = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 
    mgr.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT); 
    } 
});