Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use FontAwesome icons in Android's Jetpack Compose Icon composable?

I found option to use FontAwesomeCompose (https://github.com/Gurupreet/FontAwesomeCompose) but I am not interested in it as it is old (Dec 12, 2021) and based on free FA icons, I will have access to icons in paid version.

So second option I have on mind is to probably use somehow SVG provided by Font Awesome. But how to apply it to Icon composable, is such way that this icons will have universal 24.dp width and 24.dp height no matter which FA icon I will choose?

Or maybe there is some other simple way offered by Jetpack Compose to work with Font Awesome icons?

like image 387
PiotrW Avatar asked Oct 21 '25 04:10

PiotrW


1 Answers

I ended up importing SVG file from FA, using New -> Vector asset, without changing its default size, and giving them names similar to FA file name (ie. fa_calendar for calendar.svg, fa_calendar_week for calendar-week.svg, etc.).

Then I just use it in Icon composable:

Icon(
    painter = painterResource(id = R.drawable.fa_calendar),
    contentDescription = null,
    modifier = Modifier
        .size(48.dp)
        .clickable(onClick = ...)
        .padding(12.dp)
)

In this way I have clickable composable with size 48x48 (which is easily clickable) containing FA icon with 24x24 size.

like image 170
PiotrW Avatar answered Oct 22 '25 19:10

PiotrW



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!