本文介紹了editText 沒有失去焦點的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
當我點擊它時,editText 在我的應用程序中沒有失去焦點,它一直有橙色邊框和那個黑線光標..我根據editText周圍的這個做了一個LinearLayout:停止 EditText 在 Activity 啟動時獲得焦點所以它不會專注于應用程序的啟動..
the editText is not losing focus in my app when I click out of it, it has the orange border all time and that black line cursor.. I did this a LinearLayout according to this surrounding the editText: Stop EditText from gaining focus at Activity startup so it doesn't get focus on start of the app..
這是我的代碼:
final EditText et = (EditText)findViewById(R.id.EditText01);
final InputMethodManager imm = (InputMethodManager) getSystemService(
INPUT_METHOD_SERVICE);
et.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
imm.showSoftInput(et, InputMethodManager.SHOW_IMPLICIT);
}
});
et.setOnFocusChangeListener(new View.OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasfocus) {
if(hasfocus) {
imm.showSoftInput(et, InputMethodManager.SHOW_IMPLICIT);
} else {
imm.hideSoftInputFromWindow(et.getWindowToken(), 0);
}
}
});
但是,當我點擊editText之外的任何地方時,它似乎并沒有調用onFocusChange!
But, it doesn't seem to be calling the onFocusChange when I click anywhere outside the editText!
推薦答案
很簡單.您可以將以下內容放入 LinearLayout 或其他任何內容中:
It's simple. You can put the following in LinearLayout or any other else:
android:focusableInTouchMode="true"
這篇關于editText 沒有失去焦點的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!