本文介紹了如何以編程方式在我的 EditText 上設置焦點(并顯示鍵盤)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我有一個布局,其中包含一些這樣的視圖:
I have a layout which contains some views like this:
<LinearLayout>
<TextView...>
<TextView...>
<ImageView ...>
<EditText...>
<Button...>
</linearLayout>
如何以編程方式在我的 EditText
上設置焦點(顯示鍵盤)?
How can I set the focus (display the keyboard) on my EditText
programmatically?
我試過這個,它只有在我正常啟動我的 Activity
時才有效,但是當我在 TabHost
中啟動它時,它就不起作用了.
I've tried this and it works only when I launch my Activity
normally, but when I launch it in a TabHost
, it doesn't work.
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 上設置焦點(并顯示鍵盤)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!