Jetpack Compose collapsing toolbar

Jetpack Compose implementation of Material Design 3 includes 4 types of Top App Bars (https://m3.material.io/components/top-app-bar/implementation): CenterAlignedTopAppBar SmallTopAppBar MediumTopAppBar LargeTopAppBar https://developer.android.com/reference/kotlin/androidx/compose/material3/package-summary They all have a scrollBehavior parameter, which can be used for collapsing the toolbar. There are 3 basic types of scroll behavior in the library: TopAppBarDefaults.pinnedScrollBehavior TopAppBarDefaults.enterAlwaysScrollBehavior TopAppBarDefaults.exitUntilCollapsedScrollBehavior https://developer.android.com/reference/kotlin/androidx/compose/material3/TopAppBarDefaults Note: This API is annotated as … 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

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()

Android MVVM ViewModel and Repositories for each entity?

1 You should have contextual DAOs, let’s say an UserDao which should contains the queries related to the users, if you have posts in your app, you should have a PostDao for everything related to posts. 2 Same logic for repositories, remember the Single Responsibility Principle for classes, sticking to that principle you should have … Read more

How to use string resources in Android Jetpack Compose?

There’s androidx.compose.ui.res package containing functions for loading string resources as well as other resource types. string You can get a string using stringResource() function, for example: … import androidx.compose.ui.res.stringResource @Composable fun StringResourceExample() { Text( // a string without arguments text = stringResource(R.string.app_name) ) Text( // a string with arguments text = stringResource(R.string.greeting, “World”) ) } … Read more

How to create rounded border Button using Jetpack Compose

To achieve a button with a border with rounded corners you can use the OutlinedButton component applying in the shape parameter a RoundedCornerShape: OutlinedButton( onClick = { }, border = BorderStroke(1.dp, Color.Red), shape = RoundedCornerShape(50), // = 50% percent // or shape = CircleShape colors = ButtonDefaults.outlinedButtonColors(contentColor = Color.Red) ){ Text( text = “Save” ) … Read more

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