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

禁用 EditText 上下文菜單

Disable EditText context menu(禁用 EditText 上下文菜單)
本文介紹了禁用 EditText 上下文菜單的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在為傳統的蒙古語制作一個垂直的 EditText.我已經通過在旋轉的 ViewGroup 中嵌入稍微修改的 EditText 來成功實現它.我需要創建一個完全自定義的上下文菜單,因為系統不支持垂直文本,并且在旋轉 ViewGroup 時也不會旋轉.所以我想完全禁用系統上下文菜單.

請注意,這與這些只是試圖禁用復制/粘貼/等的問題不同:

  • 在我運行 Android 5.0 的小米 MIUI 手機上,我在所有情況下(光標句柄單擊、長按、雙擊)都會獲得上下文菜單.

    更新

    Aritra Roy 的解決方案可以在模擬器、他測試過的其他一些設備以及我的設備上運行.我接受了他的回答,因為它解決了我原來的問題.唯一的負面影響是文本選擇也被禁用??.

    解決方案

    解決方案很簡單

    公共類 MainActivity 擴展 AppCompatActivity {編輯文本 et_0;@覆蓋protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);et_0 = findViewById(R.id.et_0);et_0.setCustomSelectionActionModeCallback(new ActionMode.Callback() {@覆蓋public boolean onCreateActionMode(ActionMode mode, Menu menu) {//保持文本選擇功能可用(選擇光標)返回真;}@覆蓋public boolean onPrepareActionMode(ActionMode mode, Menu menu) {//防止菜單出現menu.clear();返回假;}@覆蓋public boolean onActionItemClicked(ActionMode mode, MenuItem item) {返回假;}@覆蓋公共無效 onDestroyActionMode(ActionMode 模式) {}});}}

    I am making a vertical EditText for traditional Mongolian. I have successfully implemented it by embedding a slightly modified EditText inside of a rotated ViewGroup. I need to create a completely custom context menu because the system one does not support vertical text and is also not rotated when the ViewGroup is rotated. So I want to disable the system context menu altogether.

    Note that this is different than these questions that are just trying to disable copy/paste/etc.:

    • How to disable copy/paste from/to EditText
    • EditText: Disable Paste/Replace menu pop-up on Text Selection Handler click event
    • how to disable paste option in android EditText
    • Android: How to TOTALLY disable copy and paste function in Edittext

    Although I don't get the context menu appearing in the simulator, I get it appearing in my Android 5.0.2 Xiaomi phone.

    I have tried:

    • the setCustomSelectionActionModeCallback "solution"
    • the setLongClickable(false); "solution"
    • the onTouchEvent "solution"

    I'm open to hacks but I need it to consistently work across devices. Mark Murphy (a Commons Guy) wrote some time back in reply to another user trying to do something similar:

    I suspect that even if you come up with an answer, it will not work across devices. Device manufacturers have had a tendency to roll their own "context menu" for EditText, defeating developers' attempts to add items into that context menu. My guess is that trying to block that context menu will have similar results.

    Am I out of luck?

    The only thing I can think of now is to completely rewrite TextView and EditText from scratch (well, by modifying the Android source). I know someone else who did something similar, but his code isn't open source. Before I take this major step, I want to try asking for a simpler solution here on Stack Overflow.

    Update: I've been trying modify the TextView source code for the past two days and it looks like a 6 month project. It is a mass of interrelated classes. I need another solution, but I am out of ideas.

    MVCE

    This is the simplest way I could think of to recreate the problem. There is nothing necessary from my custom EditText. The layout has a single EditText made by replacing the default project Hello World's TextView. I changed the min API to 11 to avoid dealing with deprecated methods.

    public class MainActivity extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            EditText editText = (EditText) findViewById(R.id.edit_text);
            editText.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
                @Override
                public boolean onCreateActionMode(ActionMode actionMode, Menu menu) { return false; }
                @Override
                public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) { return false; }
                @Override
                public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) { return false; }
                @Override
                public void onDestroyActionMode(ActionMode actionMode) { }
            });
        }
    }
    

    The context menu in the simulator (running API 24) still shows when I click on the cursor handle (but not on a long click or double click). Here is an image:

    On my Xiaomi MIUI phone running Android 5.0, I get the context menu in all situations (cursor handle click, long click, double click).

    Update

    Aritra Roy's solution is working in the simulator, on some other devices that he has tested, and on my device. I have accepted his answer because it solves my original problem. The only negative side effect is that text selection is also disabled.

    解決方案

    the solution is very simple

    public class MainActivity extends AppCompatActivity {
    
    EditText et_0;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    
        et_0 = findViewById(R.id.et_0);
    
        et_0.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
            @Override
            public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                //to keep the text selection capability available ( selection cursor)
                return true;
            }
    
            @Override
            public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                //to prevent the menu from appearing
                menu.clear();
                return false;
            }
    
            @Override
            public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                return false;
            }
    
            @Override
            public void onDestroyActionMode(ActionMode mode) {
    
            }
        });
       }
    }
    

    這篇關于禁用 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 中的數值?)
主站蜘蛛池模板: 国产区在线观看 | 亚洲国产中文字幕 | 亚洲欧美日韩国产综合 | 在线观看av网站永久 | 全免费a级毛片免费看视频免 | 欧美日韩成人在线 | 天天躁日日躁狠狠的躁天龙影院 | av在线天堂 | 亚洲美女天堂网 | 视频一区在线播放 | 国产精品久久久久久久久久 | 国产精品久久久久久久岛一牛影视 | 日韩视频在线一区 | 99视频在线播放 | 欧美日韩在线综合 | 国产精品成人一区 | 久久精品免费一区二区三 | 国产精品成人av | 亚洲欧美一区二区三区视频 | 亚洲精品久久久一区二区三区 | 精品亚洲一区二区 | 中文字幕一区二区三区在线视频 | 草比网站 | 羞羞网站免费 | 一区二区免费在线观看 | 国产一区二区在线免费观看 | 在线亚洲免费 | 一区二区三区精品 | 国产精品成人免费 | 欧美成人a∨高清免费观看 91伊人 | 亚洲国产精品一区在线观看 | 999热视频| www.国产一区 | 成人在线精品 | 久久精品欧美一区二区三区麻豆 | 亚洲成人综合在线 | 日韩在线播放网址 | 啪视频在线| 久久精品国产v日韩v亚洲 | 中文字幕久久精品 | 天天影视亚洲综合网 |