title: Disable EditText context menu
body: <p>I am making a vertical <code>EditText</code> for traditional Mongolian. I have successfully implemented it by embedding a slightly modified <code>EditText</code> inside of a rotated <code>ViewGroup</code>. 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 <code>ViewGroup</code> is rotated. So I want to disable the system context menu altogether.</p>
  
  <p>Note that this is different than these questions that are just trying to disable copy/paste/etc.:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/6275299/how-to-disable-copy-paste-from-to-edittext">How to disable copy/paste from/to EditText</a></li>
  <li><a href="https://stackoverflow.com/questions/27869983/edittext-disable-paste-replace-menu-pop-up-on-text-selection-handler-click-even">EditText: Disable Paste/Replace menu pop-up on Text Selection Handler click event</a></li>
  <li><a href="https://stackoverflow.com/questions/23100691/how-to-disable-paste-option-in-android-edittext">how to disable paste option in android EditText</a></li>
  <li><a href="https://stackoverflow.com/questions/26175041/android-how-to-totally-disable-copy-and-paste-function-in-edittext">Android: How to TOTALLY disable copy and paste function in Edittext</a></li>
  </ul>
  
  <p>Although I don't get the context menu appearing in the simulator, I get it appearing in my Android 5.0.2 Xiaomi phone. </p>
  
  <p>I have tried:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/a/22756538/3681880">the <code>setCustomSelectionActionModeCallback</code> "solution"</a></li>
  <li><a href="https://stackoverflow.com/a/13821250/3681880">the <code>setLongClickable(false);</code> "solution"</a></li>
  <li><a href="https://stackoverflow.com/a/30490027/3681880">the <code>onTouchEvent</code> "solution"</a></li>
  </ul>
  
  <p>I'm open to hacks but I need it to consistently work across devices. Mark Murphy (a Commons Guy) <a href="https://groups.google.com/forum/#!topic/android-developers/I2mh75F8cGY" rel="noreferrer">wrote</a> some time back in reply to another user trying to do something similar:</p>
  
  <blockquote>
    <p>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.</p>
  </blockquote>
  
  <p>Am I out of luck? </p>
  
  <p>The only thing I can think of now is to completely rewrite <code>TextView</code> and <code>EditText</code> 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. </p>
  
  <p><strong>Update:</strong> I've been trying modify the <code>TextView</code> 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.</p>
  
  <p><strong>MVCE</strong></p>
  
  <p>This is the simplest way I could think of to recreate the problem. There is nothing necessary from my custom <code>EditText</code>. The layout has a single <code>EditText</code> made by replacing the default project Hello World's <code>TextView</code>. I changed the min API to 11 to avoid dealing with deprecated methods.</p>
  
  <pre><code>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) { }
          });
      }
  }
  </code></pre>
  
  <p>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:</p>
  
  <p><a href="https://i.stack.imgur.com/ccexJ.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ccexJ.png" alt="enter image description here"></a></p>
  
  <p>On my Xiaomi MIUI phone running Android 5.0, I get the context menu in all situations (cursor handle click, long click, double click).</p>
  
  <h3>Update</h3>
  
  <p>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.</p>