Androidでコピーイベントを無効にする方法は?

Android アプリケーションでコピーイベントを無効にするには、次の方法を使用できます。

  1. android:textIsSelectable=”false”
<TextView
    android:id="@+id/textView"
    android:text="This text cannot be copied"
    android:textIsSelectable="false"
    ... />
  1. android.text.method.アローキー移動法
  2. android.text.method.MovementMethod
TextView textView = findViewById(R.id.textView);
textView.setText("This text cannot be copied");
textView.setMovementMethod(null);
  1. テキストビュー
  2. onTextContextMenuItem()
public class NonCopyableTextView extends TextView {
    // ...

    @Override
    public boolean onTextContextMenuItem(int id) {
        // 屏蔽复制事件
        return id == android.R.id.copy || super.onTextContextMenuItem(id);
    }
}

そして、レイアウトファイル内で NonCopyableTextView を TextView の代わりに使用してください:

<com.example.myapplication.NonCopyableTextView
    android:id="@+id/textView"
    android:text="This text cannot be copied"
    ... />

これらの手段によりアプリ中のテキストのコピーとコピーイベントのトリガーを禁止できます。ただし、これらの手段は長押しによるユーザーのテキストコピーのみを制限でき、スクリーンショットなどの他の手段によるテキストコピーを完全に防止することはできないためご注意ください。

bannerAds