Android implements a floating toolbar that can be used for text selection

Android implements a floating toolbar that can be used for text selection

To implement a floating toolbar for text selection, make the following changes in your existing app:

  1. In the View object or Activity object, change the ActionMode call from startActionMode(Callback) to startActionMode(Callback, ActionMode.TYPE_FLOATING).
  2. Instead, extend ActionMode.Callback2 with an existing implementation of ActionMode.Callback.
  3. Overrides the onGetContentRect() method to provide the coordinates of a Rect content object (such as a text selection rectangle) in the view.
  4. If the positioning of the rectangle is no longer valid, and this is the only element that needs to be declared invalid, call the invalidateContentRect() method.

Note that if you're using Android Support Library revision 22.2, the Mini Toolbar is not backwards compatible and appcompat gets control of the ActionMode object by default. This suppresses the floating toolbar. To enable AppCompatActivity support in ActionMode, call getDelegate(), then call AppCompatDelegate on the returned setHandleNativeActionModesEnabled() object with the input parameter set to false. This call returns control of the ActionMode object to the framework. On devices running Android 6.0 (API level 23), the framework can support either ActionBar mode or floating toolbar mode; on devices running Android 5.1 (API level 22) or earlier, the framework only supports ActionBar mode.
text selection

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325842569&siteId=291194637