Edittext that make selection on long click but do not show context menu?

后端 未结 2 1082
广开言路
广开言路 2021-01-17 02:37

i want to provide custom handlers that cut,copy text.

Target on Longclick

  1. Context Menu Should not appear.
  2. Text could get selected with tracker
2条回答
  •  日久生厌
    2021-01-17 02:53

    Finally I have sorted this out. This solution perfectly works for me. First of all, you need to create the context menu background as follows

    menuback.xml

    
      
        
          
            
          
        
      
    

    Then Create your Custom Menu as follows

    mymenu.xml

    
      
        
      
    

    Now add the following lines on your

    styles.xml

    
    
    
    
    
    
    

    And Finally set elevation of the actionbar to 0 and implement the ActionMode.CallBack as follows

           EditText editText=findViewById(R.id.ed);
    
        getSupportActionBar().setElevation(0);
        editText.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
            @Override
            public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                mode.getMenu().clear();
                MenuInflater inflater=mode.getMenuInflater();
                inflater.inflate(R.menu.mymenu,menu);
                return true;
            }
    
            @Override
            public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                return false;
            }
    
            @Override
            public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                return false;
            }
    
            @Override
            public void onDestroyActionMode(ActionMode mode) {
    
            }
        });
    

    Ta...da... Here is the Final Result

提交回复
热议问题