How to add an item to the text selection popup menu?

前端 未结 1 1739
感动是毒
感动是毒 2020-12-15 15:16

When the user marks some text (inside of an EditText, WebView...) a floating text selection popup appears, where apps can add custom items. Can som

1条回答
  •  甜味超标
    2020-12-15 15:36

    This blog tutorial will show you how: https://medium.com/google-developers/custom-text-selection-actions-with-action-process-text-191f792d2999

    Basically, in your Manifest file, add PROCESS_TEXT intent filter to the activity that will handle the text shared from popup menu.

    
      
        
        
        
      
    
    

    Then, you would process that text in your Activity like this

    @Override
    protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.process_text_main);
      CharSequence text = getIntent()
          .getCharSequenceExtra(Intent.EXTRA_PROCESS_TEXT);
      // process the text
    }
    

    0 讨论(0)
提交回复
热议问题