What’s difference between “= remember” and ” by remember” (Kotlin, Jetpack Compose)

It is just for convenience, to shortify syntax. By using delegate (by keyword) you can skip relating to value because it is done under the hood. In the documentation you can read There are three ways to declare a MutableState object in a composable: val mutableState = remember { mutableStateOf(default) } var value by remember … Read more

How to avoid tinting Icon with painterResource().It paints my vector in Black

The Icon applies a default tint based on LocalContentColor.current that is Black by default. Use tint= Color.Unspecified to avoid it: Icon( painter = painterResource(id = R.drawable.ic_google_logo), contentDescription = “Google Button”, tint= Color.Unspecified ) The other option is to use an Image instead of an Icon.

Android: Jetpack Compose and XML in Activity

If you want to use a Compose in your XML file, you can add this to your layout file: <androidx.compose.ui.platform.ComposeView android:id=”@+id/my_composable” android:layout_width=”wrap_content” android:layout_height=”wrap_content” /> and then, set the content: findViewById<ComposeView>(R.id.my_composable).setContent { MaterialTheme { Surface { Text(text = “Hello!”) } } } If you want the opposite, i.e. to use an XML file in your compose, … Read more

ViewModels creation is not supported in Preview

You could use an approach that looks like this which will show up in the recommended video bellow: @Composable fun TestView( action: MainActions, viewModel: OnboardViewModel = getViewModel() ) { TestUI(onClick = viewModel.clickMethod()) } @Composable fun TestUI(onClick: () -> Unit) {} @Preview @Composable fun TestUIPreview() { MaterialTheme() { TestUI(onClick = {}) } } There is a … Read more