Soft keyboard doesn't appear

廉价感情. 提交于 2019-12-30 20:06:11

问题


I'm testing my app on android 4.0.4 Samsung galaxy duos, the problem is if I set:

android:textIsSelectable="true"

the keyboard doesn't appear, though it appears on the emulator. Any suggestions?

Here is how my EditBox looks like

<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 />

回答1:


Add a requestfocus. In xml:

<EditText>
    <requestFocus />
</EditText>  

Programmatically

edittext.requestFocus();

To "force" the SoftKeyboard to appear, you can do it dynamically:

InputMethodManager mImm = (InputMethodManager) 
                        getSystemService(Context.INPUT_METHOD_SERVICE);  
mImm.showSoftInput(SearchEdit, InputMethodManager.SHOW_IMPLICIT);  

Set onFocusChangeListener to appear your keyboard:

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);  
   } 
});  

See InputMethodManager Documentation for more information.
See also these answers to forcing the Keyboard to appear: Forcing the Soft Keyboard open




回答2:


You need to put requestFocus inside EditText element:

<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 />
<EditText/>


来源:https://stackoverflow.com/questions/20512984/soft-keyboard-doesnt-appear

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!