软键盘不会出现

dak*_*ait 5 android android-layout android-edittext

我在Android 4.0.4三星galaxy duos上测试我的应用程序,问题是如果我设置:

android:textIsSelectable="true"
Run Code Online (Sandbox Code Playgroud)

键盘没有出现,虽然它出现在模拟器上.有什么建议?

这就是我的EditBox样子

<EditText 

        android:focusable="true"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"        
        android:inputType="textVisiblePassword|textCapWords|textMultiLine"
        android:textIsSelectable="true"
        android:gravity="top|left"
        android:minLines="6"
        android:maxLines="10"
        android:minHeight="140dp"
        android:hint="@string/message"
        />
      <requestFocus />
Run Code Online (Sandbox Code Playgroud)

fll*_*llo 7

添加requestfocus.在xml中:

<EditText>
    <requestFocus />
</EditText>  
Run Code Online (Sandbox Code Playgroud)

编程

edittext.requestFocus();
Run Code Online (Sandbox Code Playgroud)

要"强制"出现SoftKeyboard,您可以动态执行:

InputMethodManager mImm = (InputMethodManager) 
                        getSystemService(Context.INPUT_METHOD_SERVICE);  
mImm.showSoftInput(SearchEdit, InputMethodManager.SHOW_IMPLICIT);  
Run Code Online (Sandbox Code Playgroud)

设置onFocusChangeListener以显示键盘:

edittext.setFocusable(true);  
edittext.setOnFocusChangeListener(new View.OnFocusChangeListener() {  
   @Override  
   public void onFocusChange(View v, boolean hasFocus) {  
       if (hasFocus)   
           mImm.showSoftInput(SearchEdit, InputMethodManager.SHOW_IMPLICIT);  
       else  
           mImm.hideSoftInputFromWindow(edittext.getWindowToken(), 0);  
   } 
});  
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请参阅InputMethodManager文档.
另请参阅这些强制键盘出现的答案:强制打开软键盘