如何以编程方式在我的EditText上设置焦点(并显示键盘)

我有一个布局,其中包含这样的一些意见:

<LinearLayout>
<TextView...>
<TextView...>
<ImageView ...>
<EditText...>
<Button...>
</linearLayout>

如何以编程方式在我的EditText上设置焦点(显示键盘)?

我试过这个,它只在我正常启动我的Activity ,但是当我在TabHost启动它时,它不起作用。

txtSearch.setFocusableInTouchMode(true);
txtSearch.setFocusable(true);
txtSearch.requestFocus();

尝试这个:

EditText editText = (EditText) findViewById(R.id.myTextViewId);
editText.requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);

http://developer.android.com/reference/android/view/View.html#requestFocus()


使用:

editText.requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);

showSoftInput根本不适合我。

我想我需要设置输入模式: android:windowSoftInputMode="stateVisible" (这里在清单中的Activity组件中)

希望这个帮助!

链接地址: http://www.djcxy.com/p/93375.html

上一篇: How can I set the focus (and display the keyboard) on my EditText programmatically

下一篇: Get soft keyboard height in fullscreen mode