Add App Share Button Like Tell a Friend – Kotlin | Android Studio

Add share button on your created app using Kotlin, And engage more user. So add simple code on your project.

How to Do

Paste this code for button on ActivityMain.xml

<Button
    android:id="@+id/share_btn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Tell a friend" />

Then paste functionality code on MainActivity.kt file –

val share_btn : Button = findViewById(R.id.share_btn)

share_btn.setOnClickListener {
val intent= Intent()
intent.action=Intent.ACTION_SEND
intent.putExtra(Intent.EXTRA_TEXT,"Enter_value")
intent.type="text/plain"
startActivity(Intent.createChooser(intent,"Share To:"))
}

Add these simple code and add share button on your Android application.