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

從 EditText 禁用軟鍵盤但仍允許復制/粘貼?

Disable soft-keyboard from EditText but still allow copy/paste?(從 EditText 禁用軟鍵盤但仍允許復制/粘貼?)
本文介紹了從 EditText 禁用軟鍵盤但仍允許復制/粘貼?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

您好,我正在制作自定義撥號器,所以我創建了自己的輸入板.

Hi I'm making custom dialer so I create my own input pad.

問題是如何禁用 EditText 但仍允許剪切/復制/粘貼?股票撥號器可以做到這一點.

The problem is how do I disable the EditText but still allow cut/copy/paste? The stock dialer can do this.

我試過 android:focusable="false" 但它禁用剪切/復制(但仍然可以粘貼).

I have tried android:focusable="false" but it disables cut/copy (can still paste though).

我還嘗試以編程方式禁用 inputType,這會禁用所有三個命令:

I also tried to disable the inputType programatically which disables all three commands:

myEditText.setInputType(InputType.TYPE_NULL); //Can't cut/copy/paste

從清單中禁用它也不起作用:

Disabling it from manifest also doesn't work:

android:configChanges="orientation|keyboardHidden" //Keyboard still popped up

有什么解決辦法嗎?謝謝

Any solution? Thanks

推薦答案

經過數小時的研究,我終于找到了適用于所有 API 版本的解決方案.希望這可以節省一些人的時間.

After hours and hours of research, I finally found a solution that works for all API versions. Hope this saves someone's time.

如果您正在為 API >= 11 進行開發,則解決方案很簡單:

If you are developing for API >= 11, the solution is simple, either:

1) 在EditText的xml文件中添加以下兩個屬性

1) Add the two properties below in the xml file of EditText

android:inputType="none"
android:textIsSelectable="true"

2) 以編程方式執行以下操作

2) Programatically do the below

myEditText.setInputType(InputType.TYPE_NULL);
myEditText.setTextIsSelectable(true);

你已經完成了.

如果你想滿足 API <11 同樣,我發現如果您想選擇文本進行復制粘貼,則無法禁用鍵盤彈出.將 focusable 設置為 false 將禁用鍵盤,但它無濟于事,因為它也會禁用您選擇文本的能力.我在 stackoverflow 中找到的任何其他解決方案都不起作用或同時禁用文本選擇.

If you want to cater for API < 11 as well, I found that there is no way to disable to keyboard from popping out if you wanted to select the text for copy paste purpose. Setting focusable to false will disable the keyboard but it doesn't help because it disables your ability to select text too. Any other solutions I found in stackoverflow all either doesn't work or disables text selection at the same time too.

解決這個問題的一個丑陋的方法就是這樣......

One ugly way to solve this is as such..

首先,在EditText的xml文件中添加這個屬性

First, add this property in the xml file of EditText

android:editable="false"

是的,這已被棄用,但有必要在 API 版本中使 EditText 不可編輯

11.

Yes this is deprecated, but necessary for making the EditText not editable in API version < 11.

接下來,我們需要在鍵盤出現時立即隱藏它,這樣我們就可以繼續選擇文本而不會被鍵盤擋住.

Next, we will need to hide the keyboard as soon as it shows up, so that we can continue selecting text without the keyboard blocking the way.

使用下面的代碼檢測鍵盤是否出現(解決方案來自 https://stackoverflow.com/a/9108219/1241783),并立即隱藏它.

Use this code below to detect keyboard showing up (solution obtained from https://stackoverflow.com/a/9108219/1241783), and hide it immediately.

if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB)
{
    final View activityRootView = findViewById(R.id.activityRoot);
    activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
    @Override
        public void onGlobalLayout() {
            Rect r = new Rect();
            //r will be populated with the coordinates of your view that area still visible.
            activityRootView.getWindowVisibleDisplayFrame(r);

            int heightDiff = activityRootView.getRootView().getHeight() - (r.bottom - r.top);
            if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...

            //Hide the keyboard instantly!
            if (getCurrentFocus() != null) 
            {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
            }
            }
         }
        });
}

它適用于我的情況.盡管您可以在一瞬間看到鍵盤出現(這是丑陋的部分),但在撰寫本文時我想不出任何其他方法可以使其正常工作.如果您有更好的解決方案,請發表評論!

It works for my case. Though you can see the keyboard showing up in a split second (which is the ugly part) but I can't think of any other way to get this to work at the time of writing. If you have a better solution, please leave a comment!

如果這樣可以節省某人的時間,請告訴我:)

Let me know too if this saves someone's time :)

這篇關于從 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 中的數值?)
主站蜘蛛池模板: 国产99久久精品一区二区永久免费 | 一级a性色生活片久久毛片波多野 | 欧美日韩成人在线观看 | 国产视频一区二区在线观看 | 91高清视频在线观看 | 99re视频在线观看 | 亚洲精品永久免费 | 久久黄网 | 久草免费在线视频 | 精品久久久久久久久久久 | 性欧美精品一区二区三区在线播放 | 亚洲精品性视频 | 亚洲欧美综合精品另类天天更新 | 精品日韩一区二区三区 | 国产美女在线观看 | 天堂色| 久久久久久999 | 久久新 | 超黄视频网站 | 免费成人高清在线视频 | 久久精品黄色 | 亚洲一区二区在线电影 | 亚洲网在线| 国产精品视频一区二区三区不卡 | 亚洲三区在线播放 | 99久久精品免费看国产四区 | 久久6视频 | 成人国产精品入口免费视频 | 中文字幕二区三区 | 91精品在线观看入口 | 欧美jizzhd精品欧美巨大免费 | 一级片成人 | 日本一区二区三区视频在线 | 亚洲精品www| 91免费小视频 | 国产精品自产拍在线观看蜜 | 国产乱码精品一区二区三区五月婷 | www国产成人免费观看视频 | 欧美成人精品激情在线观看 | 亚洲第一av | 婷婷丁香综合网 |