Android Jetpack Compose – Text Maximum Lines

Android Jetpack Compose – Text Maximum Number of Lines

To set maximum number of lines of text that can be displayed in a Text composable in Android Jetpack Compose, you can set the maxLines parameter with the required integer value.


In the following example, we have set the text of the Text composable to a maximum of two lines.

If you do not specify any value for maxLines parameter, the Text composable would display three lines, as there as three lines.


package com.example.myapplication

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.ui.Modifier
import com.example.myapplication.ui.theme.MyApplicationTheme

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        setContent {
            MyApplicationTheme {
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colorScheme.background
                ) {
                        text = "Hello Android!\nThis is sample text.\nAnd another line.",
                        maxLines = 2


Android Jetpack Compose - Text Maximum Number of Lines
Text maxLines=2


In this tutorial, we have seen how to set maximum number of lines of text in Text composable to be displayed, in Android Jetpack Compose, using maxLines parameter of Text composable.