Disable EditText context menu

前端 未结 7 1261
花落未央
花落未央 2020-11-28 13:54

I am making a vertical EditText for traditional Mongolian. I have successfully implemented it by embedding a slightly modified EditText inside of a

相关标签:
7条回答
  • 2020-11-28 14:55

    This is a hard problem. I've spent hours and hours researching and testing in my Android Studio 3.4.2.

    I propose 3 steps:

    a) the setCustomSelectionActionModeCallback "solution" in the original question But it keeps showing the select handles (red drop under the cursor) and "Clipboard + Select All" popup, when you click in the red drop.

    b) Create a empty image for select handles. I've created a file called ic_empty.xml under res/drawable.

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
    </shape>
    

    c) I've created a style in style.xml for all EditTexts.

    Under main theme

     <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
            ...
            <item name="android:editTextStyle">@style/TStyle</item>
            ....
     </style>
    

    So you can define you style associating an empty image for lef, middle, and right select handles:

       <style name="TStyle" parent="@android:style/Widget.EditText" >
            <item name="android:textSelectHandle">@drawable/ic_empty</item>
            <item name="android:textSelectHandleLeft">@drawable/ic_empty</item>
            <item name="android:textSelectHandleRight">@drawable/ic_empty</item>
        </style>
    

    If the target is from API 23 one can use setTextAppearance for attach a style in a text inside a EditText. However, the above solution works always

    The only remaining problem is that I can rid of double click effect. It selects a word in the text, with pink background. However, it is relatively harmless, but awkward, because it does not require user interaction.

    A trick that can be done it's set the highlight color transparent.

    EditT.setHighlightColor(Color.TRANSPARENT)  // EditT is a EditText
    
    0 讨论(0)
提交回复
热议问题