[英]Kotlin Custom Android Keyboard IME - method onUpdateCursorAnchorInfo from InputMethodService is not working
[英]Detect EditText pressed outside of custom keyboard (IME) Android
我正在開發一個帶有搜索框的 android 鍵盤。 我可以檢測到用戶何時按下我的搜索框,然后將他鍵入的文本提交到我的搜索框中。
問題是我無法檢測到用戶何時按下原始 EditText(打開鍵盤的那個),因為這不是我的觀點。
這是鍵盤的基本外觀:
鍵盤被藍色方塊包圍,我的編輯文本被紅色方塊包圍。
我嘗試在我的 editText 上設置這個監聽器,但沒有運氣:( 來源)
editText.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
if (hasFocus) {
Toast.makeText(getApplicationContext(), "Got the focus", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "Lost the focus", Toast.LENGTH_LONG).show();
}
}
});
當我按下另一個 editText 時,沒有調用偵聽器。 可能是因為它不是我的服務的一部分。
即使我可以知道如何檢測在我的服務布局之外的屏幕上的點擊,它也會很棒。
謝謝你的幫助!
盡管您的問題非常基本,但我想我可以在這里提供幫助,請嘗試以下代碼片段,並告訴我它是否適合您。
public void showKeyboard(View view) {
InputMethodManager myKeyboard = (InputMethodManager) getSystemService(Context
.INPUT_METHOD_SERVICE);
myKeyboard.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
public void hideKeyboard() {
InputMethodManager myKeyboard = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
myKeyboard.hideSoftInputFromWindow(EditText1.getWindowToken(), 0);
}
這也是一個重復的問題,請參見此處: Android:當焦點位於 EditText 時自動顯示軟鍵盤
請在此處發布問題之前嘗試使用 ol' 谷歌,當您等待其他人對您的帖子發表評論時,它會大大拖延您的進度:) 如果您發布重復的問題並且沒有得到足夠的答案,也可以作為旁注對您的帖子進行投票,Stack Overflow 可以禁止您發帖。
您也可以查看有關此主題的 Android 開發人員文檔: https : //developer.android.com/training/keyboard-input/visibility
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.