久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

當軟鍵盤出現時,它使我的 EditText 字段失去焦點

When the soft keyboard appears, it makes my EditText field lose focus(當軟鍵盤出現時,它使我的 EditText 字段失去焦點)
本文介紹了當軟鍵盤出現時,它使我的 EditText 字段失去焦點的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我在 ListView 中有幾個 EditText 字段.當我點擊其中一個 EditText 字段時,鍵盤會滑入視圖(應該如此),但我點擊的 EditText 字段失去焦點.我嘗試使用各種 InputMethodManager 方法使鍵盤在視圖中啟動(為了解決問題而不是真正解決它),但這不起作用 - 當 Activity 出現時鍵盤不在視圖中.

I've got a few EditText fields in a ListView. When I tap on one of the EditText fields, the keyboard slides into view (as it should), but the EditText field I tapped loses focus. I've tried using various InputMethodManager methods to make the keyboard start out in view (in order to get around the problem rather than truly solve it), but that didn't work - the keyboard was not in view when the Activity appeared.

EditText的類型是number,當鍵盤滑入的時候是數字鍵盤,但是當滑完EditText失去焦點后,變成字母鍵盤(加強了EditText 不再具有焦點的想法).

The EditText's type is number, and when the keyboard is sliding in, it is a number keyboard, but when it finishes sliding and the EditText loses focus, it changes to the alphabetical keyboard (which reinforces the idea that the EditText no longer has focus).

我的問題是:

1) 如何選擇我的 EditText 字段以及隨后滑入軟鍵盤不會使我的 EditText 失去焦點?

1) How can I make the selection of my EditText field and the subsequent sliding in of the soft keyboard not make my EditText lose focus?

...失敗了...

2) 我怎樣才能讓鍵盤一開始就在視野中,這樣它就不必滑入(從而避免我認為如此令人反感的行為)?

2) How can I make the keyboard start out in view so it never has to slide in (thus avoiding the behavior I find so objectionable)?

我的清單確實包含 android:windowSoftInputMode="stateAlwaysVisible",但在我點擊 EditText 之前鍵盤不會出現.這種對stateAlwaysVisible"屬性的忽略似乎只發生在模擬器中——在我配置的設備上,這是很榮幸的,所以上面的問題 2 確實適用于設備......但不適用于模擬器.

My manifest does include android:windowSoftInputMode="stateAlwaysVisible", but the keyboard does not appear until I tap on an EditText. This ignoring of the 'stateAlwaysVisible' attribute seems to only occur in the emulator - on my provisioned device, it is honored so question number 2 above does work on the device... but not in the emulator.

感謝您提供的任何幫助!

Thanks for any help you can provide!

推薦答案

這就是我的做法.onFocusChangeListener() 會在您觸摸 EditText 以在其中鍵入文本時多次調用.順序是:

Here is how I did it. The onFocusChangeListener() is called several times when you touch a EditText to type text into it. The sequence is:

  1. 如果焦點位于不同的視圖上,則該視圖失去焦點
  2. 目標獲得焦點
  3. 彈出軟鍵盤.
  4. 這會導致目標失去焦點
  5. 代碼檢測到這種情況并調用 target.requestFocus()
  6. 由于 Android 的胡說八道,最左側、最頂部的視圖獲得焦點
  7. 由于調用 requestFocus,最左邊的視圖失去焦點
  8. 目標終于獲得焦點

  1. If focus was on a different view, then that view loses focus
  2. The target gains focus
  3. Soft keyboard pops up.
  4. This causes the target to lose focus
  5. The code detects this situation and calls target.requestFocus()
  6. The leftmost, topmost view gains focus, due to Android nonsense
  7. The leftmost view loses focus, due to requestFocus being called
  8. Target finally gains focus

//////////////////////////////////////////////////////////////////
private final int minDelta = 300;           // threshold in ms
private long focusTime = 0;                 // time of last touch
private View focusTarget = null;

View.OnFocusChangeListener onFocusChangeListener = new View.OnFocusChangeListener() {
    @Override
    public void onFocusChange(View view, boolean hasFocus) {
        long t = System.currentTimeMillis();
        long delta = t - focusTime;
        if (hasFocus) {     // gained focus
            if (delta > minDelta) {
                focusTime = t;
                focusTarget = view;
            }
        }
        else {              // lost focus
            if (delta <= minDelta  &&  view == focusTarget) {
                focusTarget.post(new Runnable() {   // reset focus to target
                    public void run() {
                        focusTarget.requestFocus();
                    }
                });
            }
        }
    }
};

上面的代碼適用于鍵盤彈出窗口.但是,它不會檢測到語音到文本的彈出窗口.

The code above works well for the keyboard pop-ups. However, it does not detect the speech-to-text pop-up.

這篇關于當軟鍵盤出現時,它使我的 EditText 字段失去焦點的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Cut, copy, paste in android(在android中剪切、復制、粘貼)
android EditText blends into background(android EditText 融入背景)
Change Line Color of EditText - Android(更改 EditText 的線條顏色 - Android)
EditText showing numbers with 2 decimals at all times(EditText 始終顯示帶 2 位小數的數字)
Changing where cursor starts in an expanded EditText(更改光標在展開的 EditText 中的開始位置)
EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView問題)
主站蜘蛛池模板: 天天操网 | 成人在线免费观看视频 | 亚洲国产精品99久久久久久久久 | 久久久精品视频一区二区三区 | 欧美激情视频一区二区三区在线播放 | 日韩一级一区 | 精品视频一区二区 | 亚洲一区影院 | 日韩精品视频网 | 一区在线播放 | 日韩精品在线视频免费观看 | 欧美精品久久久久 | 久久免费精品 | 欧美激情免费在线 | 免费三级黄 | 青草久久免费视频 | 日韩成人一区 | 久久这里有精品 | 国产精品久久久久一区二区三区 | 日韩伦理一区二区 | 久久大 | 国产精品久久久久久婷婷天堂 | 黄色精品 | 精品视频一区二区三区 | 亚洲精品中文字幕 | 日本高清不卡视频 | 日韩视频在线一区 | 久久久久久艹 | 五月槐花香 | 欧美日韩国产高清视频 | 日日夜夜天天 | 中文字幕第一页在线 | 日韩欧美一级精品久久 | 亚洲视频国产 | 欧洲精品码一区二区三区免费看 | 久草视频在线播放 | h肉视频| 亚洲免费在线观看 | 成人精品鲁一区一区二区 | 精品一区二区三区在线视频 | av成人在线观看 |