Home > front end >  How to Copy Text to Clip Board in Compose?
How to Copy Text to Clip Board in Compose?

Time:05-08

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?

CodePudding user response:

I think this is what you need.

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