Mahdi Razzaghi
Mahdi Razzaghi

Reputation: 383

How to Copy Text to Clip Board in Compose?

simple question: How to Copy Text to Clip Board in Compose?

before Compose we used to do something like this:

val clipboardManager = getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
val clipData = ClipData.newPlainText(
    content_et.getText().toString()
)
clipboardManager.setPrimaryClip(clipData)
Toast.makeText(this@MainActivity, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show()

what we should do in compose?

Upvotes: 3

Views: 2877

Answers (1)

nglauber
nglauber

Reputation: 23964

I think this is what you need.

val clipboardManager = LocalClipboardManager.current
clipboardManager.setText(AnnotatedString("Some text"))

Upvotes: 12

Related Questions