Error when adding buildFeatures in build.gradle file

I caught this error when I tried to add Jetpack to my existing app. I followed Suraj’s answer, even used the newest Kotlin gradle plugin, and couldn’t exactly figure out what was wrong. I also followed the official setup guide and it didn’t work. Everything seemed okay, but nothing helped. Installing Android Studio 4.0 canary … Read more

How do I load url into Image into DrawImage in Compose UI Android Jetpack?

Staring with 1.0.x the best way to achieve it is to use the Coil-Compose library. Add in your build.gradle the dependency dependencies { implementation(“io.coil-kt:coil-compose:1.3.1”) } Then just use: Image( painter = rememberImagePainter(“your url”), contentDescription = “My content description”, ) This loads the url passed in with rememberImagePainter, and then displays the resulting image using the … Read more

Get height of element Jetpack Compose

If you want to get the height of your button after composition, then you could use: onGloballyPositionedModifier. It returns a LayoutCoordinates object, which contains the size of your button. Example of using onGloballyPositioned Modifier: @Composable fun OnGloballyPositionedExample() { // Get local density from composable val localDensity = LocalDensity.current // Create element height in pixel state … Read more

Jetpack Compose: Custom TextField design

You can use the TextField: removing the label with label = null applying custom color with the TextFieldDefaults.textFieldColors parameter to hide the indicator. adding in the onValueChange a function to fix the max number of characters as described here Finally use a Column to add 2 Text composables to complete the external label and counter … Read more

How can I render plain android ProgressBar with Compose?

Ofcourse, we have Progress Bars in Jetpack Compose: CircularProgressIndicator: Displays progress bar as Circle. It is indeterminate. Themed to Primary color set in styles. Another variant is determinate that takes progress in argument as Float (0.0f – 1.0f) Example: // Indeterminate CircularProgressIndicator() // Determinate CircularProgressIndicator(progress = 0.5f) LinearProgressIndicator: Displays progress bar as line. It is … Read more

Using LiveData as state inside Jetpack @Compose functions

Here is another way to observe live data using state. There is an extension function for this just include it. add gradle dependency below one: implementation ‘androidx.compose.runtime:runtime-livedata:1.0.0-beta01’ now just convert your regular LiveData to State for example. val breedItems by doggoViewModel.liveBreedData().observeAsState()

Jetpack compose: Setting ImeAction does not close or change focus for the keyboard

You can use keyboardOptions: software keyboard options that contains configuration such as KeyboardType and ImeAction keyboardActions when the input service emits an IME action, the corresponding callback is called For Done: You can use the LocalSoftwareKeyboardController to interact with the keyboard. keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done), keyboardActions = KeyboardActions( onDone = {keyboardController?.hide()} ) For Next: … Read more

Where can I put the `suppressKotlinVersionCompatibilityCheck` flag?

I have the same problem with message: e: This version (1.0.0-alpha11) of the Compose Compiler requires Kotlin version 1.4.21-2 but you appear to be using Kotlin version 1.4.21 which is not known to be compatible. Please fix your configuration (or `suppressKotlinVersionCompatibilityCheck` but don’t say I didn’t warn you!). Adding compiler args solved my problem: “-P”, … Read more

What is the ItemDecoration for Jetpack Compose LazyColumn?

You can use the verticalArrangement parameter to add a spacing between each item using Arrangement.spacedBy(). Something like: LazyColumn( verticalArrangement = Arrangement.spacedBy(8.dp), ) { // … } The example below adds 8.dp of space in-between each item Before and after: If you want to add padding around the edges of the content you can use the … Read more