+ // Add a Copy Text entry if the link text is not null.
+ if (linkText != null) {
+ contextMenu.add(R.string.copy_text).setOnMenuItemClickListener {
+ // Save the link URL in a clip data.
+ val srcAnchorTypeTextClipData = ClipData.newPlainText(getString(R.string.copy_text), linkText)
+
+ // Set the clip data as the clipboard's primary clip.
+ clipboardManager.setPrimaryClip(srcAnchorTypeTextClipData)
+
+ // Consume the event.
+ true
+ }
+ }
+