2011-08-08 41 views

回答

0

可能出现的情况:

1)单击EditText时,通常会出现键盘。但是,如果您按下模拟器中的后退键按钮,键盘(而不是屏幕键盘)变暗。

2)在代码中,您可以通过设置标志来禁用键盘上的EditText。

InputMethodManager inputmethodmgr= (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 
inputmethodmgr.hideSoftInputFromWindow(myEditText.getWindowToken(), 0); 
24

好的,这可能是一个迟到的反应,但它的工作。

我在android 2.1和2.3.x上遇到了这个问题(未在其他版本的SDK上测试过)。

我注意到一个奇怪的事情,当我点击EditText无法打开键盘时,我按下BACK按钮来显示一个警告对话框,然后我取消(关闭)它,并再次单击EditText,现在键盘被重新赋予生命。

,从我可以得出结论,键盘将始终显示为的EditText如果EditText上没有以前自己的焦点(显示在EditText上查看警报对话框会让的EditText失去焦点)。

这样称呼了以下功能在您的EditText当它被带到面前:

mEditText.clearFocus(); 

parentViewThatContainsEditTextView.clearFocus(); 
2

在我的情况下,它是在一个PopupWindow,我只是需要调用popupWindow.setFocusable(true)

3

这里有一个可能的解决方案:

editText.setOnFocusChangeListener(new OnFocusChangeListener() { 
    @Override 
    public void onFocusChange(final View v, final boolean hasFocus) { 
     if (hasFocus && editText.isEnabled() && editText.isFocusable()) { 
      editText.post(new Runnable() { 
       @Override 
       public void run() { 
        final InputMethodManager imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE); 
        imm.showSoftInput(editText,InputMethodManager.SHOW_IMPLICIT); 
       } 
      }); 
     } 
    } 
}); 

代码是基于下一链接:

http://turbomanage.wordpress.com/2012/05/02/show-soft-keyboard-automatically-when-edittext-receives-focus/

7

我对银河S3类似的问题(显示的EditText上的PopupWindow控制 - 键盘从未示出)。这解决了我的问题:

final PopupWindow popUp = new PopupWindow(vbl.getMainLayout()); 
[....] 
popUp.setFocusable(true); 
popUp.update(); 
3

我不想EditText使用editText.clearFocus()失去焦点。来到这个解决方案。

@Override 
public void onResume() { 
    super.onResume(); 

    if (Build.VERSION.SDK_INT < 11) { 
     editText.clearFocus(); 
     editText.requestFocus(); 
    } 
} 
1

它就像一个魅力,如果你甚至想隐藏点击edittextView隐藏的情况。

textView.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      displayKeyboard(); 
     } 
    }); 

private void displayKeyboard(){ 
    if (textView != null) { 
     InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 
     imm.toggleSoftInputFromWindow(textView.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0); 
    } 
} 
+0

是的,但有了办法,你会得到意想不到的行为。例如,如果您在IMM被强制打开的情况下为应用程序提供背景,则即使在主屏幕上,它也会保持打开状态。 :) – worked

相关问题