Last active
March 17, 2021 14:20
-
-
Save abircse/c23f5beed82a2a380b4319bf1af1996c to your computer and use it in GitHub Desktop.
CustomDialogWithItemAction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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