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

當(dāng)軟鍵盤出現(xiàn)時(shí),它使我的 EditText 字段失去焦點(diǎn)

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

問題描述

限時(shí)送ChatGPT賬號(hào)..

我在 ListView 中有幾個(gè) EditText 字段.當(dāng)我點(diǎn)擊其中一個(gè) EditText 字段時(shí),鍵盤會(huì)滑入視圖(應(yīng)該如此),但我點(diǎn)擊的 EditText 字段失去焦點(diǎn).我嘗試使用各種 InputMethodManager 方法使鍵盤在視圖中啟動(dòng)(為了解決問題而不是真正解決它),但這不起作用 - 當(dāng) Activity 出現(xiàn)時(shí)鍵盤不在視圖中.

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,當(dāng)鍵盤滑入的時(shí)候是數(shù)字鍵盤,但是當(dāng)滑完EditText失去焦點(diǎn)后,變成字母鍵盤(加強(qiáng)了EditText 不再具有焦點(diǎn)的想法).

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 字段以及隨后滑入軟鍵盤不會(huì)使我的 EditText 失去焦點(diǎn)?

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) 我怎樣才能讓鍵盤一開始就在視野中,這樣它就不必滑入(從而避免我認(rèn)為如此令人反感的行為)?

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)?

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

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() 會(huì)在您觸摸 EditText 以在其中鍵入文本時(shí)多次調(diào)用.順序是:

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. 如果焦點(diǎn)位于不同的視圖上,則該視圖失去焦點(diǎn)
  2. 目標(biāo)獲得焦點(diǎn)
  3. 彈出軟鍵盤.
  4. 這會(huì)導(dǎo)致目標(biāo)失去焦點(diǎn)
  5. 代碼檢測到這種情況并調(diào)用 target.requestFocus()
  6. 由于 Android 的胡說八道,最左側(cè)、最頂部的視圖獲得焦點(diǎn)
  7. 由于調(diào)用 requestFocus,最左邊的視圖失去焦點(diǎn)
  8. 目標(biāo)終于獲得焦點(diǎn)

  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();
                    }
                });
            }
        }
    }
};

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

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

這篇關(guān)于當(dāng)軟鍵盤出現(xiàn)時(shí),它使我的 EditText 字段失去焦點(diǎn)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Cut, copy, paste in android(在android中剪切、復(fù)制、粘貼)
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 位小數(shù)的數(shù)字)
Changing where cursor starts in an expanded EditText(更改光標(biāo)在展開的 EditText 中的開始位置)
EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView問題)
主站蜘蛛池模板: 久久综合影院 | 欧美精品一区二区三区在线播放 | 国产精品综合一区二区 | 福利在线看 | 欧美国产精品一区二区三区 | 亚洲精品中文字幕 | 国产欧美一区二区三区日本久久久 | heyzo在线| 黄色毛片免费 | 国产精品亚洲综合 | 99re6在线| 播放一级毛片 | 九九导航 | 亚洲一区二区三区在线视频 | 成人午夜免费网站 | 欧美精品成人一区二区三区四区 | 日本不卡免费新一二三区 | 亚洲 欧美 另类 日韩 | 国产激情91久久精品导航 | 在线观看亚洲 | 久久r久久 | 精品一区二区视频 | 男人的天堂久久 | 欧美一区二区三区在线观看视频 | 国产高清在线精品 | 日韩精品无码一区二区三区 | 国产精品日女人 | 亚洲精品久久视频 | 国产无人区一区二区三区 | 亚洲最大成人综合 | 99久久婷婷国产综合精品电影 | 国产欧美日韩综合精品一区二区 | 国产免费观看视频 | 性天堂网| 亚洲视频免费在线播放 | 午夜小影院 | 国产精品久久精品 | 国产区在线 | 蜜桃视频在线观看免费视频网站www | 久久久久国产精品一区二区 | 成人在线精品视频 |