How to access any icon in jetpack compose? - android-jetpack-compose

I have tried the following method still it shows Unresolved reference: Calculate error
Icon needed -
calculate
import androidx.compose.material.Icon Icon( Icons.Rounded.Calculate, contentDescription = "" )
Dependency used :
dependencies{ implementation "androidx.compose.material:material-icons-extended:$compose_version"}

Try this, it works for me:
Icon(
imageVector = Icons.Rounded.Calculate,
contentDescription = "Icon",
tint = Color.White
)

Related

Compose Column with vertical scrollable modifier not working

I am trying to create a similar-to-scrollview behavior with Jetpack Compose, which should be simple but I find it not working (I can't scroll the Column). I have been following the example from here:
https://github.com/vinaygaba/Learn-Jetpack-Compose-By-Example/blob/master/app/src/main/java/com/example/jetpackcompose/scrollers/VerticalScrollableActivity.kt#L104
And this is my code:
#Composable
fun MainScreen() {
val scrollState = rememberScrollState()
Column(
modifier = Modifier
.fillMaxSize()
.scrollable(
state = scrollState,
orientation = Orientation.Vertical
)
) {
Text(
text = "This is my first Compose App",
fontSize = 24.sp,
fontWeight = FontWeight.Light,
lineHeight = 40.sp,
color = Color.Black,
modifier = Modifier.padding(top = 32.dp, start = 24.dp)
)
Row(
modifier = Modifier
.fillMaxWidth()
.background(Color(0xFF6A0DAD))
.height(2200.dp))
{}
}
}
as mentioned #bylazy using Modifier.verticalScroll(scrollState) solves it

Error "Cannot find a parameter with this name: brush" in Jetpack Compose

I copied the below code from BrushExampleSnippet.kt but the compiler gives an error that it can't find brush, I double checked import but it's correct as import androidx.compose.ui.text.TextStyle.
// Use ImageShader Brush with TextStyle
Text(
text = "Hello Android!",
style = TextStyle(
brush = imageBrush, // here brush parameter is not found.
fontWeight = FontWeight.ExtraBold,
fontSize = 36.sp
)
)
Brush API was added to TextStyle by compose 1.2.0.

Display the correct colors of a logo in a icon in compose [duplicate]

This question already has answers here:
How to avoid tinting Icon with painterResource().It paints my vector in Black
(2 answers)
Closed 7 months ago.
I have the following composable
#Composable
fun GoogleLoginButton(onLoginClicked: () -> Unit) {
IconButton(
modifier = Modifier
.fillMaxWidth()
.background(color = Color.White, shape = RoundedCornerShape(10.dp)),
onClick = {
onLoginClicked()
},
) {
Box(modifier = Modifier.fillMaxWidth(),
contentAlignment = Alignment.Center) {
Icon(
modifier = Modifier.padding(start = 12.dp).align(Alignment.CenterStart),
painter = painterResource(id = R.drawable.ic_google_logo),
contentDescription = "Google logo"
)
Text(modifier = Modifier.fillMaxWidth(),
textAlign = TextAlign.Center,
fontSize = 18.sp,
text = "Google", color = Color.Black)
}
}
}
It displays the correct logo for for some reason its displayed as black icon.
However, the actual colors of the vector image is this:
Icon has a tint argument which is set to LocalContentColor by default. Either set it to Color.Unspecified, or use Image composable instead.

How do I fix ConstraintLayout that include Balloon(gives strange results) in jetpack compose?

I'm trying to make a help pop ups in my first app. the problem that came up after making the pop up work is that the icon which I'm using becomes a button taking up whole screen height.
I'm using the only code I found for balloon popups in jetpack compose.
the layout is fine until I add the BalloonAnchor.
this is the code:
#Composable
fun GiveHelp(helpText: String) {
Surface{
val context = LocalContext.current
val lifecycleOwner = LocalLifecycleOwner.current
ConstraintLayout {
val (icon, text) = createRefs()
Icon(
modifier = Modifier
.constrainAs(icon) {
top.linkTo(parent.top)
start.linkTo(parent.start)
},
painter = painterResource(id = R.drawable.ic_help),
contentDescription = "help Icon"
)
Text(
modifier = Modifier
.constrainAs(text) {
top.linkTo(icon.top)
start.linkTo(icon.end)
bottom.linkTo(icon.bottom)
}
.padding(horizontal = 10.dp),
text = "Is your task:"
)
BalloonAnchor(
reference = icon,
modifier = Modifier
.aspectRatio(0.1f),
balloon = BalloonUtils.getTitleBalloon(
context = context,
title = helpText,
lifecycle = lifecycleOwner
),
onAnchorClick = { balloon, anchor -> balloon.showAlignTop(anchor) }
)
}
}
}
The problem here is the aspectRatio you are using in the Modifier of BalloonAnchor. Try something like Modifier.aspectRatio(0.99f). Using this, your Icon will not take the entire screen height. Or, your can use something like below code to get a desirable look.
BalloonAnchor(
reference = icon,
modifier = Modifier
.height(40.dp),
balloon = BalloonUtils.getTitleBalloon(
context = context,
title = helpText,
lifecycle = lifecycleOwner
),
onAnchorClick = { balloon, anchor -> balloon.showAlignTop(anchor) }
)

Jetpack compose Justified and RTL Text

In jetpack Compose, you can Justify a Text like this:
Text(
text = text,
textAlign = TextAlign.Justify
)
If you want support RTL, you achive this by:
Text(
text = text,
textAlign = TextAlign.Right
)
How can a Text() support RTL text and justify it same time in Jetpack Compose?
After several hour testing, I reach this:
#Composable
fun JustifiedRTLText(
text: String,
modifier: Modifier = Modifier
) {
CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Rtl) {
Text(
text = text,
textAlign = TextAlign.Justify,
modifier = modifier,
)
}
}
In Jetpack Compose RTL or LTR will automatically set by according to the text content. But we can force it by changing the textDirection of style to TextDirection.Content or TextDirection.RTL
Text(
text = text,
textAlign = TextAlign.Justify,
style = TextStyle(textDirection = TextDirection.Content)
)

Resources