Material3 Color Harmonization in Jetpack Compose - android

While using the view-based system, we can harmonize a color using the below code.
MaterialColors.harmonizeWithPrimary(context, colorToHarmonize)
In a project that is fully migrated to Jetpack Compose and all the color values are stored in the Color.kt file, how do you apply harmonization to color at runtime?

Related

Can't override the TextFieldColors textColor in Jetpack Compose

I'm trying to customize the colors of a TextField of Jetpack Compose. For this I'm creating an instance of TextFieldColors where I set the textColor to one of my custom colors. But the result has been that the TextField keeps using the default colors.
I been reading that this could be modified with a CompositionLocalProvider, but then why is there an option on TextFieldColors? Also, changing it with CompositionLocal wouldn't allow for more than one custom color on my TextFields.
Some ilustrations of the problem, the first picture shows the TextField in light mode, the text can't be seen on dark mode because it doesn't change to from the default black. All the other parts of the component change corretly, since they are using my custom colors.
Is there a way to achieve this?
Also I'm using Material 2, would it make any difference to change to M3?

Android Jetpack Compose using same elevation value

Hi, I want to migrate my apps to android jetpack compose and create custom card like this. But, when I try to using my trick on xml (using same elevation value) to create shadow around the card, I can't generate the same result.
How can this be achieved using jetpack compose?

How to learn material 3 component attribute use case

Can someone help me on Material 3. I found this two method darkColorScheme and lightColorScheme . When I checked the definition of this function I found so many colors used in the function. I am confused which one using where so, Is there any documentation or blog where this type of attribute is using i.e. secondaryContainer, tertiary etc. this is few example I want to learn each attribute where this is using according to their name. I am new in material design with jetpack compose.
Jetpack Compose functions darkColorScheme and lightColorScheme help you set up a whole MD3 theme with all the color roles.
You would want to set/define all colors if you want that background and foreground colors will work nicely together.
The mapping for colors can be found at
https://m3.material.io/styles/color/the-color-system/color-roles
See the sections for Mapping accent colors and for Mapping neutral colors
However, you don't have to set all colors manually. If you want you can use the theme builder, and only choose your primary, secondary, tertiary and neutral color and the theme will be generated for you (there are also extended colors if you need more). If you export it for Jetpack Compose you will get both Theme.kt and Color.kt which you then copy and replace in your project. The calls to darkColorScheme and lightColorScheme will be already included with all colors already set as parameters. If you don't like any of the mapped colors, you can then customize the theme further in code.
The theme builder https://material-foundation.github.io/material-theme-builder/#/custom
The documentation on how to use themed colors is from this section and on
https://developer.android.com/jetpack/compose/themes/material#theme-colors
Material Design 3 components (buttons, inputs, text) will by default already use themed colors based on the defined theme, light/dark modes and the surface they are on, so for common use cases you don't even need to set their colors through parameters or modifiers.
Edit: To preview various MD3 components quickly without the need to run the app you can use the #Preview annotation like this
#Preview("Light Mode")
#Preview("Dark Mode", uiMode = Configuration.UI_MODE_NIGHT_YES)
#Composable
fun MyScreenPreview() {
NameOfYourTheme { // update this line with the name of your theme
Surface {
// place any Composable you want to preview here
Column {
Text("Preview test")
Button(onClick = {}) {
Text("OK")
}
}
}
}
}
You can place this in any file you want and then just replace the contents with various MD3 components to see how they look in the preview section both in light and dark mode with your theme.
And if you want to see their default colors, then just remove the NameOfYourTheme { } block.
For the above this is what I get for my theme in the preview section (your colors will be different of course)

I can't find ModalBottomSheetLayout in material3 with jetpack compose?

Recently I created a project using material3 with jetpack compose but when I tried to import ModalBottomSheetLayout but I couldn't find it. Is there any alternate in material3 or not ?
In previous material version we do like :-
ModalBottomSheetLayout(sheetContent = ) {
}
Based on this package summary it is not currently available in Material 3 for Compose.

Jetpack Compose theming at runtime from network api call

I have an API call for theming that returns all colors for my application. I want to apply these colors all of jetpack components. can anyone please suggest a proper way to do this.
I have two files theme. kt and color. kt .
I need to change values in these classes dynamically.
you should receive your colors from API then store that in dataStore then observe your data store in the main theme compose function whenever colors changed then create a new color pallet then set that in your MaterialTheme. automatically everywhere used MaterialTheme colors are updated.

Categories

Resources