I want to make corners of ConstraintLayout rounded without using CardView. My current code is this but not working
ConstraintLayout(
modifier
.fillMaxWidth()
.clip(RoundedCornerShape(100.dp))
)
{...}
It is working guys, I just added background after clip() and it's working fine.
Related
In XML we have material3 bottom navigation bar style. It's color achieved by using surface color with elevation = 3dp. So in XML higher elevation means lighter background color.
I'm trying to implement same behavior in Compose. But it looks like elevation in Compose doesn't change bottom navigation's color but only adding shadow. So can we apply same behavior in Compose somehow or the only way is to add separate bottom nav's color in Color.kt?
BottomNavigation(
modifier = Modifier.heightIn(80.dp),
backgroundColor = MaterialTheme.colorScheme.surface,
elevation = 3.dp
)
You are probably not using material3 library but the old one. There is no BottomNavigation composable in material3, it's called NavigationBar and it has tonalElevation argument instead of elevation that does what you want.
Hi I am creating an app with Jetpack Compose I am and using Card composable with elevation. I need to change the elevation color, but I don't know how.
You can use the shadow modifier. For example:
modifier = Modifier
.shadow(ambientColor = Color.Blue, elevation = 15.dp)
I'm facing a weird issue with the latest stable version of Jetpack compose. When I was using version 1.0.5 everything was fine with LazyColumn
I'm migrating an app from Jetpack compose version 1.0.5 to 1.1.1
but when I run the app, it shows some vertical gap between the LazyColumn items
When I checked, the contentPadding it still 0.dp on the LazyDsl.kt
contentPadding: PaddingValues = PaddingValues(0.dp)
I also haven't used any verticalArrangement
TIA
After spending lots of hours, I found that the padding was generated by onClick on JetpackCompose Card. I fixed it using Modifier.clickable{} as below:
Before
Card(
elevation = paddingZero,
onClick = {
// listener here
}
)
After
Card(
elevation = paddingZero,
modifier = Modifier.clickable {
// listener here
}
)
This fixed my issue. I hope this can be helpful to someone who is having same issue.
In a project I am creating, I want to have a transparent floating button button in one of my screens.
The button should be of a color RGB(126,26,71), with 75% alpha channel.
But, when I create said button composable, it looks like this:
As you can see, it has slightly white, transparent background as well
This is how the composable is created:
FloatingActionButton(
onClick = {//TODO},
backgroundColor = MediumOpaquePurple, //the color I specified above
elevation = FloatingActionButtonDefaults.elevation(Space8)
)
{
Icon(
imageVector = Icons.Default.Delete,
contentDescription = "Delete notifications"
)
}
Weird thing is that when I use the same color for ExtendedFloatingActionButton composable, it looks perfectly fine and there's no white background in it.
Any help apprectiated.
Thanks
For FloatingActionButton the solution is to set elevation(0.dp). Just omitting the call is not enough, because it has a default value of 6.dp.
ExtendedFloatingActionButton acts a bit differently and does need this tweaking.
In Jetpack Compose the clickable Modifier will by default use LocalIndication.current and show a ripple that is bound to the border. That looks great almost always, but there are some circumstances where a rounded, unbound ripple looks better. Back in View Android we would've used android:background="?attr/selectableItemBackgroundBorderless to achieve this behaviour. How can we do it in compose?
Example [source]:
You can customise the ripple effect as follow:
Modifier.clickable(
interactionSource = remember { MutableInteractionSource() },
indication = rememberRipple(bounded = false), // You can also change the color and radius of the ripple
onClick = {}
)