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

EditText,清晰專注于觸摸外

EditText, clear focus on touch outside(EditText,清晰專注于觸摸外)
本文介紹了EditText,清晰專注于觸摸外的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我的布局包含 ListView、SurfaceViewEditText.當我單擊 EditText 時,它會獲得焦點并彈出屏幕鍵盤.當我單擊 EditText 之外的某個位置時,它仍然具有焦點(它不應該).我想我可以在布局中的其他視圖上設置 OnTouchListener 并手動清除 EditText 的焦點.但似乎太 hackish...

My layout contains ListView, SurfaceView and EditText. When I click on the EditText, it receives focus and the on-screen keyboard pops up. When I click somewhere outside of the EditText, it still has the focus (it shouldn't). I guess I could set up OnTouchListener's on the other views in layout and manually clear the EditText's focus. But seems too hackish...

我在其他布局中也有相同的情況 - 具有不同類型項目的列表視圖,其中一些具有 EditText 的內部.他們的行為就像我上面寫的一樣.

I also have the same situation in the other layout - list view with different types of items, some of which have EditText's inside. They act just like I wrote above.

任務是讓 EditText 在用戶觸摸外部的東西時失去焦點.

The task is to make EditText lose focus when user touches something outside of it.

我在這里看到過類似的問題,但沒有找到任何解決方案...

I've seen similar questions here, but haven't found any solution...

推薦答案

我嘗試了所有這些解決方案.edc598 最接近工作狀態,但觸摸事件并未在布局中包含的其他 View 上觸發.如果有人需要這種行為,我最終會這樣做:

I tried all these solutions. edc598's was the closest to working, but touch events did not trigger on other Views contained in the layout. In case anyone needs this behavior, this is what I ended up doing:

我創建了一個名為 touchInterceptor 的(不可見的)FrameLayout 作為布局中的最后一個 View,以便它覆蓋所有內容(edit: 您還必須使用 RelativeLayout 作為父布局并賦予 touchInterceptor fill_parent 屬性).然后我用它來攔截觸摸并確定觸摸是否在 EditText 之上:

I created an (invisible) FrameLayout called touchInterceptor as the last View in the layout so that it overlays everything (edit: you also have to use a RelativeLayout as the parent layout and give the touchInterceptor fill_parent attributes). Then I used it to intercept touches and determine if the touch was on top of the EditText or not:

FrameLayout touchInterceptor = (FrameLayout)findViewById(R.id.touchInterceptor);
touchInterceptor.setOnTouchListener(new OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            if (mEditText.isFocused()) {
                Rect outRect = new Rect();
                mEditText.getGlobalVisibleRect(outRect);
                if (!outRect.contains((int)event.getRawX(), (int)event.getRawY())) {
                    mEditText.clearFocus();
                    InputMethodManager imm = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); 
                    imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
                }
            }
        }
        return false;
    }
});

返回 false 讓觸摸處理失敗.

Return false to let the touch handling fall through.

這很hacky,但它是唯一對我有用的東西.

It's hacky, but it's the only thing that worked for me.

這篇關于EditText,清晰專注于觸摸外的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

EditText: Disable Paste/Replace menu pop-up on Text Selection Handler click event(EditText:禁用文本選擇處理程序單擊事件上的粘貼/替換菜單彈出)
Multiline EditText with Done SoftInput Action Label on 2.3(2.3 上帶有完成 SoftInput 操作標簽的多行 EditText)
How to detect the swipe left or Right in Android?(如何在 Android 中檢測向左或向右滑動?)
Prevent dialog dismissal on screen rotation in Android(防止在Android中的屏幕旋轉對話框解除)
How do I handle ImeOptions#39; done button click?(如何處理 ImeOptions 的完成按鈕點擊?)
How do you set EditText to only accept numeric values in Android?(您如何將 EditText 設置為僅接受 Android 中的數值?)
主站蜘蛛池模板: 琪琪午夜伦伦电影福利片 | 一区视频在线播放 | 成人欧美一区二区三区黑人孕妇 | 日本 欧美 国产 | a视频在线| 日韩一区二区三区视频 | 久久久久久国产精品 | 日韩在线视频免费观看 | 亚洲精品在线视频 | 国产91精品久久久久久久网曝门 | 日韩在线观看一区 | 91国产精品 | 一区二区三区欧美大片 | 美女久久 | 久久精品国产久精国产 | 日本成人综合 | 亚洲精品视频播放 | 国产精品国产三级国产aⅴ原创 | 国产精品亚洲一区二区三区在线 | 毛片毛片毛片毛片毛片 | 午夜一级大片 | 午夜丰满少妇一级毛片 | 偷拍第一页 | 国产成人精品一区二区三 | 日韩欧美亚洲 | 自拍视频在线观看 | 成人午夜免费福利视频 | 视频一区 国产精品 | 日批免费观看 | 中文字幕综合 | 成人综合久久 | 国产精品不卡 | 九九热在线精品视频 | 亚洲一区二区视频 | 久久久久久免费毛片精品 | 欧美高清dvd | 免费久久网站 | 久久一及片 | 91成人免费看片 | 日日夜夜精品视频 | 理论片午午伦夜理片影院 |