Android Jetpack Compose Icons doesn’t contain some of the material icons

There’s a separate dependency material-icons-extended which contains the full list of material icons, just add it into your app’s build.gradle dependencies { … implementation “androidx.compose.material:material-icons-extended:$compose_version” } Now you can use any material icon, for example: … import androidx.compose.material.Icon import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Menu // ok import androidx.compose.material.icons.filled.Print // ok @Composable fun IconsExample() { Icon(Icons.Filled.Menu, “menu”) // … Read more

Jetpack Compose LazyColumn programmatically scroll to Item

The LazyListState supports the scroll position via the scrollToItem() function, which ‘immediately’ snaps the scroll position, animateScrollToItem() which scrolls using an animation Something like: val listState = rememberLazyListState() // Remember a CoroutineScope to be able to launch val coroutineScope = rememberCoroutineScope() LazyColumn(state = listState) { // … } Button ( onClick = { coroutineScope.launch { … Read more

How to handle visibility of a Text in Jetpack Compose?

As CommonsWare stated, compose being a declarative toolkit you tie your component to a state (for ex: isVisible), then compose will intelligently decide which composables depend on that state and recompose them. For ex: @Composable fun MyText(isVisible: Boolean){ if(isVisible){ Text(text = stringResource(id = R.string.hello)) } } Also you could use the AnimatedVisibility() composable for animations.

Pass Parcelable argument with compose navigation

Warning: Ian Lake is an Android Developer Advocate and he says in this answer that pass complex data structures is an anti-pattern (referring the documentation). He works on this library, so he has authority on this. Use the approach below by your own. Edit: Updated to Compose Navigation 2.4.0-beta07 Seems like previous solution is not … Read more

android:autoSizeTextType in Jetpack Compose

I use the following to adjust the font size with respect to the available width: val textStyleBody1 = MaterialTheme.typography.body1 var textStyle by remember { mutableStateOf(textStyleBody1) } var readyToDraw by remember { mutableStateOf(false) } Text( text = “long text goes here”, style = textStyle, maxLines = 1, softWrap = false, modifier = modifier.drawWithContent { if (readyToDraw) … Read more

Create Vertical Divider Jetpack Compose

You can use the Divider composable with the width(xx.dp) modifier applying an intrinsic measurements to its parent container. Something like: Row(Modifier .height(IntrinsicSize.Min) //intrinsic measurements .fillMaxWidth() .background(Color.Yellow) ) { Text(“First Text”) Divider( color = Color.Red, modifier = Modifier .fillMaxHeight() //fill the max height .width(1.dp) ) Text(“Second text”) } As explained in the doc: The Row composable’s … Read more

Android Compose: How to use HTML tags in a Text view

There is yet no official Composable to do this. For now i’m using an AndroidView with a TextView inside. Not the best solution, but it’s simple and that solves the problem. @Composable fun HtmlText(html: String, modifier: Modifier = Modifier) { AndroidView( modifier = modifier, factory = { context -> TextView(context) }, update = { it.text … Read more