2013-10-20 49 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); 
    } 
});