Android/Kotlin

클립보드 복사

lipnus 2019. 3. 8. 15:41
반응형


클립보드 복사


class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

button.setOnClickListener {
onClick_clipboard()
}

}

fun onClick_clipboard(){

val clipboardManager = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clipData = ClipData.newPlainText("라벨", "요호호")
clipboardManager!!.setPrimaryClip(clipData)

Toast.makeText(applicationContext, "복사완료", Toast.LENGTH_LONG).show()
}
}


반응형

'Android > Kotlin' 카테고리의 다른 글

Activity - Fragment 간 Communication  (0) 2019.03.13
@JvmStatic (자바,코틀린 static매소드 연동)  (0) 2019.03.13
Dialog  (0) 2019.02.27
RxBus  (0) 2019.02.15
First-class citizen (1급객체)  (0) 2019.02.01