Search code examples
androidcontextual-action-bar

Adding more options to Android default Contextual Action Bar


Is it possible to add more options to Android default Contextual Action Bar, what I mean is not only changing it in one application, but also altering all CABs in the entire system. If it's not possible, is there any other way to write an app which reacts when I select a text in different applications (ex. browser, Gmail etc.) and make it for example pop up on the side.

I don't expect any code, just a general approach and some hints how to achieve a similar behavior.


Solution

  • Is it possible to add more options to Android default Contextual Action Bar, what I mean is not only changing it in one application, but also altering all CABs in the entire system.

    There is no "default Contextual Action Bar" in general. Certain widgets may have a default contextual action bar (a.k.a., action mode).

    Given some of the rest of your question, I am guessing that by "default Contextual Action Bar", you mean for the EditText widget (or anything else based on TextView that allows text selection).

    In that case, on Android 6.0 and higher, you can implement an ACTION_PROCESS_TEXT activity, which will be integrated as an option into the text selection floating action mode. Note that this action mode is only available in portrait mode, so your activity will not appear as an option in landscape.

    There is no similar option for Android 5.1 and earlier.

    is there any other way to write an app which reacts when I select a text in different applications

    You might be able to accomplish this by writing an AccessibilityService. Note that the user has to opt into enabling your AccessibilityService in the Settings app, which will warn the user about the privacy implications involved in allowing your app to spy on all their input.