1

我想显示软键盘,但它不起作用。这是我的代码:

 public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        myTextView myTextView = new myTextView(this);

        setContentView(myTextView);
    }

public class myTextView extends EditText{

public boolean onTouchEvent(){

if(action == ACTION_DOWN){

super.onTouchEvent(event);

} }

当我触摸屏幕时,软键盘不会出现,但会出现 alertDialog“编辑文本”,当你长时间触摸它们时,它会出现在正常的编辑文本上。onCreate 中的这个附加代码没有任何影响:

InputMethodManager input = (InputMethodManager) 
getSystemService(Context.INPUT_METHOD_SERVICE);
input.showSoftInput(myTextView, 0);

感谢您的帮助,Fr4gg0r

4

2 回答 2

0

尝试这个 -

    myTextView.setOnFocusChangeListener(
            new View.OnFocusChangeListener() {
                @Override
                public void onFocusChange(View v, boolean hasFocus) {
                    if (hasFocus)
                              getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
                }
            });
于 2010-08-15T19:28:48.227 回答
0

我很抱歉这个很晚的答案。所以我用以下命令尝试了你的代码:myTextView.requestFocus(); 但是键盘没有出现。

我必须更正我的文字:在模拟器上,键盘没有出现,但在我的三星 Galaxy S 上,它出现了!:o

于 2010-08-29T00:05:30.443 回答