How to make Text Selectable in Android using Jetpack Compose? Last Updated : 11 Jul, 2021 Comments Improve Suggest changes Like Article Like Report By default, Composable Texts are not selectable which means users cannot copy text from your application, and to enable text selection you need to wrap the text elements into Selection Container. In this article, we will use Android’s Jetpack Compose to create those chips. A sample image is given below to give an idea of what we are going to build. Note that we are going to implement this project using the Kotlin language. Step by Step Implementation Step 1: Create a New Project To create a new project in the Android Studio Canary Version please refer to How to Create a new Project in Android Studio Canary Version with Jetpack Compose. Step 2: Working with the MainActivity.kt file Navigate to the app > java > your app’s package name and open the MainActivity.kt file. Inside that file add the below code to it. Comments are added inside the code to understand the code in more detail. Kotlin import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.text.selection.DisableSelection import androidx.compose.foundation.text.selection.SelectionContainer import androidx.compose.material.MaterialTheme import androidx.compose.material.Surface import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import com.example.jetpack_playground.ui.theme.Jetpack_playgroundTheme class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { Jetpack_playgroundTheme { // A surface container using the // 'background' color from the theme Surface(color = MaterialTheme.colors.background) { // call the CustomSelectableText() function // it is defined below Column { CustomSelectableText() } } } } } } // create a composable function // for the selectable text. // Wrap the text inside SelectionContainer() // in order to make it selectable @Composable fun CustomSelectableText() { SelectionContainer() { Column() { Text( text = "Welcome to Geeks for Geeks,A Computer Science portal for geeks." + "It contains well written, well thought and well explained computer " + "science and programming articles, quizzes and ...", textAlign = TextAlign.Center, modifier = Modifier .padding(start = 10.dp, top = 20.dp) .fillMaxWidth() ) } } } @Preview(showBackground = true) @Composable fun DefaultPreview() { Jetpack_playgroundTheme { CustomSelectableText() } } Output: Comment More infoAdvertise with us Next Article How to make Text Selectable in Android using Jetpack Compose? introidx Follow Improve Article Tags : Kotlin Android Android-Jetpack Similar Reads How to Disable Text Selection in Android using Jetpack Compose? In Android, a TextView is used to display text inside the activity on the screen. Similarly, in Jetpack Compose, a Text element is used to display text on the activity screen. By default, the text displayed in the Text element cannot be selected. To do so, the Text element has to be declared inside 3 min read How to Create Outlined Text in Android using Jetpack Compose? In Android, we can customize various aspects of a Text for displaying them accordingly. We can change the font size, and font family as well as apply various functions like bold, italics, etc. However, it is not possible to display an outline font for the same text. In case, you are unaware of what 3 min read How to Remove TextField Padding in Android using Jetpack Compose? In Android Jetpack Compose, a TextField is used to take input from the user in the form of text. TextField when in focus or when clicked invokes a soft keyboard. In general, TextField is highly attributed for a better feel and appearance. However, we can use a pre-developed TextField, named BasicTex 3 min read Text in Android using Jetpack Compose Jetpack Compose is a new toolkit provided by Google. This is useful for designing beautiful UI designs. Android Text is a simple view in Android which is used to display text inside our App. In this article, we will take a look at the implementation of Text in Android using Jetpack Compose. Importan 5 min read Speech to Text Application in Android using Jetpack Compose Speech to Text is used in most applications such as Google Search for searching any query. For using this feature user simply has to tap on the microphone icon and speak the query he wants to search. The speech of the user will be converted to text. In this article, we will take a look at How we can 7 min read How to Add Margin in Android using Jetpack Compose? In Android, Padding is used to offset the content of the view by a specific number of pixels from either direction, i.e., padding from left, right, top and bottom. Using Padding, we can create multiple borders to a view by applying a combination of multiple padding and border.  So in this article, 2 min read How to Set Maximum Input Length in TextField in Android using Jetpack Compose? In Android, EditText is used to collect text-based user input inside the activity on the screen. Similarly, in Jetpack Compose, a TextField element is used to collect input text on the activity screen. By default, there is no limit to what users can type inside the TextField.  So in this article, w 3 min read Android Jetpack Compose - How to Use Phone Selector API In most android applications, we get to see that users don't have to enter their phone numbers for authentication. A pop-up message is triggered automatically which displays the phone number of the user which is present on the device. This feature helps users to easily authenticate within the applic 5 min read Tab Layout in Android using Jetpack Compose Tab Layout is seen used in most applications such as WhatsApp in which users can navigate to multiple screens easily by simply swiping to the left or right. This tab layout provides easy navigation between multiple screens. In this article, we will take a look at How we can implement Tab Layout with 7 min read How to Create Superscript and Subscript Text using Jetpack Compose in Android? In this article, we will explain how to create a Superscript and Subscript text using Jetpack Compose. Below is the sample picture to show what we are going to build. Note that we are going to implement this project using the Kotlin language. Prerequisites: Basic Knowledge of Kotlin.Jetpack Compose 2 min read Like