Androidでコピーイベントを無効にする方法は?
Android アプリケーションでコピーイベントを無効にするには、次の方法を使用できます。
- android:textIsSelectable=”false”
<TextView
android:id="@+id/textView"
android:text="This text cannot be copied"
android:textIsSelectable="false"
... />
- android.text.method.アローキー移動法
- android.text.method.MovementMethod
TextView textView = findViewById(R.id.textView);
textView.setText("This text cannot be copied");
textView.setMovementMethod(null);
- テキストビュー
- 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"
... />
これらの手段によりアプリ中のテキストのコピーとコピーイベントのトリガーを禁止できます。ただし、これらの手段は長押しによるユーザーのテキストコピーのみを制限でき、スクリーンショットなどの他の手段によるテキストコピーを完全に防止することはできないためご注意ください。