LoginSignup
12
13

More than 5 years have passed since last update.

Android 6.0 Changes - Text Selection

Last updated at Posted at 2015-11-16

なんちゃって和訳。内容未検証

  • コピペのメニューに独自のアクションを追加できるようになった
  • contextual action modeを使う場合と同じ感じで実装できる。

新しいテキスト選択ツールバーを使うには、既存実装を次の通りに直します。(訳注:多分、すでにActionModeを自前で弄っている場合の話)

  1. ViewやActivityの、startActionMode(Callback)startActionMode(Callback, ActionMode.TYPE_FLOATING)に変える
  2. ActionMode.CallbackActionMode.Callback2
  3. onGetContentRect()をオーバーライドして、viewの座標Rectオブジェクトを設定する?
    (Override the onGetContentRect() method to provide the coordinates of the content Rect object (such as a text selection rectangle) in the view.)
  4. 選択状態じゃなかったらinvalidateContentRect()を呼ぶ?
    (If the rectangle positioning is no longer valid, and this is the only element to be invalidated, call the invalidateContentRect() method.)

サポートライブラリのrev22.2を使っている場合、新しいツールバーは下位互換性がないので注意してください。デフォルトでは、appcompatActionModeオブジェクトのコントロールをします。新しいツールバーは表示されません。

AppCompatActivityActionModeサポートを有効にするには、getDelegate()の戻り値のAppCompatDelegatesetHandleNativeActionModesEnabled()falseを設定します。
これによりActionModeオブジェクトのコントロールがフレームワークに返されます。

これにより、Android 6.0(APIレベル23)の端末では、フレームワークがActionBarまたは新しいツールバーを許可し、Android 5.1(APIレベル22)以下の端末ではActionBarのみがサポートされます。


その他にPROCESS_TEXTというACTIONが増えた。マッシュルームみたいにテキストの処理を外部アプリ投げる仕組みっぽい。

Android Developers Blogでは選択したテキストをGoogle翻訳アプリに翻訳させるのを例に挙げている。
これは既にAndroid 6.0ユーザーなら使える。EditTextがあるアプリで適等に文章を入力して選択すると、選択ツールバーのオーバーフローメニューに「翻訳」と出る。

12
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
13