软键盘不会出现

时间:2013-12-11 07:25:23

标签: android android-layout android-edittext

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

android:textIsSelectable="true"

键盘没有出现,但它出现在模拟器上。有什么建议吗?

以下是我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 />

2 个答案:

答案 0 :(得分:6)

添加requestfocus。 在xml中:

<EditText>
    <requestFocus />
</EditText>  

以编程方式

edittext.requestFocus();

要“强制”显示SoftKeyboard,您可以动态执行:

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

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

有关详细信息,请参阅InputMethodManager Documentation 另请参阅这些强制键盘显示的答案:Forcing the Soft Keyboard open

答案 1 :(得分:1)

您需要将requestFocus放在EditText元素中:

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