Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Material icon size adjustment in Jetpack Compose?

Jetpack compose provides a nice Icon() object to display icons that accepts a vector asset. Typically, you are able to set the size via a modifier:

Icon(Icons.Filled.PersonPin, Modifier.preferredSize(64.dp)) 

My problem is I cannot seem to affect the size of the displayed icon when I am using a provided system vector asset (ie, Icons.Filled. or Icons.Default. etc). When I use my own asset, things work as expected. Using the system assets the modifier only increases the UI footprint of the enclosing "box" while the icon stays tiny within:

Sample from IDE Preview

Applying the modifier using 'then' results in the same behavior:

    Icon(Icons.Filled.PersonPin,Modifier.then(Modifier.preferredSize(128.dp)))

Is there something about the native icons? I assumed being vector assets they should be able to resize as well.

like image 670
Andy Avatar asked Oct 15 '20 18:10

Andy


People also ask

How do you use material icons in Jetpack Compose?

To use Icon , include the Compose Material library (or the Compose Material 3 library). By default, the Icon composable is tinted with LocalContentColor. current and is 24. dp in size.

How do I use an icon in compose?

To draw an icon, you can use the Icon composable which applies tint and provides layout size matching the icon. Some of the most commonly used icons are available as part of the androidx. compose.

How do you turn off the ripple effect when clicking in Jetpack Compose?

How to disable ripple effect in Jetpack Compose? Using the Mutable Interaction Source. Create a Custom MutableInteractionSource Class. Create a Custom No Ripple Theme.

What is Scaffold state in Jetpack Compose?

Scaffold provides slots for a top app bar or a bottom app bar. The placement of the composables is handled internally. These slots can be used for other Material Components like BottomNavigation . You can also use custom composables — for an example, take a look at the onboarding screen from the Owl sample.


1 Answers

With 1.0.x just use the Modifier.size(xx.dp)

Icon(Icons.Filled.Person,
    "contentDescription",
    modifier = Modifier.size(128.dp))
like image 55
Gabriele Mariotti Avatar answered Sep 18 '22 19:09

Gabriele Mariotti