Skip to content

Instantly share code, notes, and snippets.

@abircse
Last active March 17, 2021 14:20
Show Gist options
  • Save abircse/c23f5beed82a2a380b4319bf1af1996c to your computer and use it in GitHub Desktop.
Save abircse/c23f5beed82a2a380b4319bf1af1996c to your computer and use it in GitHub Desktop.
CustomDialogWithItemAction
val options = arrayOf<CharSequence>("Share", "Copy URL","Cancel")
val builder = AlertDialog.Builder(this)
builder.setTitle("")
builder.setCancelable(false)
builder.setItems(options) { dialog: DialogInterface, item: Int ->
if (options[item].equals("Share")) {
val intent = Intent(Intent.ACTION_SEND)
intent.type = "text/plain"
intent.putExtra(Intent.EXTRA_TEXT, YOUR_LINK)
startActivity(Intent.createChooser(intent, "Share"))
} else if (options[item].equals("Copy URL")) {
(getSystemService(CLIPBOARD_SERVICE) as ClipboardManager).apply {
setPrimaryClip(ClipData.newPlainText("link", YOUR_COPY_ITEM))
showMessage("Link Copied")
}
} else if (options[item].equals("Cancel")) {
dialog.dismiss()
}
}
builder.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment