Simplify Icon Usage in Android with the Fontawesome Android Library

TLDR;

GitHub repository

Introduction

If you are like me and don’t really know how to design a UI and mostly rely on default UI views? Then you will love this library. I created this for a personal project and wanted to share with the world. On doing so I learned how to publish a package in maven central.

Features

  • Easy integration of FontAwesome icons into Android projects.
  • Access a wide range of Font Awesome icons and use them to create drawables effortlessly.
  • Lightweight and efficient library.
  • Customizable icon size and color.
  • With Jetpack Compose Wrapper

Installation

To use the FontAwesome Icon Library in your Android project, follow these steps:

1. Add the library as a dependency in your app-level build.gradle file:

dependencies {
    implementation 'com.shirishkoirala:FontAwesome:0.2.0'
}

2. Sync your project to fetch the library from the specified dependency.

Usage

Using the FontAwesome Icon Library is straightforward but can be achieved in different ways. First, identify the desired icon from the available Font Awesome icons. You can refer to the Font Awesome website for a comprehensive list of icons. Follow any of the following ways to add icon to your project.

Creating Drawables with Font Awesome Icons and adding it to ImageView To create a drawable using a Font Awesome icon, follow these steps:

1. In your XML layout file, define an ImageView:

<ImageView
    android:id="@+id/imageView"
    android:layout_width="24dp"
    android:layout_height="24dp">

2. Create IconDrawable as following:

IconDrawable whiteGearIcon = new IconDrawable(this, Icons.gear, Color.WHITE)

3. Add it to the ImageView

ImageView imageView = (ImageView)findViewById(R.id.imageView);
imageView.setImageDrawable(whiteGearIcon);

Using IconTextView

1. Add the IconTextView widget to your layout XML file:

<com.shirishkoirala.fontawesome.IconTextView 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/gear"
    android:textColor="@color/white" 
    android:textSize="@dimen/title">

2. Change the desired icon code, size, and color in your activity or fragment:

IconTextView iconTextView = findViewById(R.id.iconTextView);
iconTextView.setText(Icons.t);
iconTextView.setTextSize(24);
iconTextView.setTextColor(this,R.color.white);

Using IconView

1. Add the IconView widget to your layout XML file:

<com.shirishkoirala.fontawesome.IconView
    android:layout_width="24dp"
    android:layout_height="24dp"
    android:src="@string/gear" 
    android:tint="@color/yellow">

2. Change the desired icon code, and color in your activity or fragment:

IconView iconView = (IconView) findViewById(R.id.iconView);
iconView.setColor(Color.RED);
iconView.setIcon(Icons.gear);

Using Jetpack Compose

ComposeIconView(
    color = R.color.black,
    modifier = Modifier.padding(it),
    size = Dp(35f)
)

Contributing to the Fontawesome Android Library

The Fontawesome Android Library is an open-source project, and contributions from the developer community are highly appreciated. Whether you find a bug, have suggestions for improvements, or want to add new features, you can contribute to the library by creating issues or submitting pull requests on the GitHub repository.

Conclusion

The Fontawesome Android Library is a valuable asset for Android developers seeking an efficient way to incorporate Font Awesome icons into their applications. With its comprehensive features, including the creation of drawables, Unicode support, and customized views, the library simplifies the process of using icons and enhances the visual appeal of Android apps.

To learn more about the Fontawesome Android Library, access the documentation, and explore the sample app, visit the GitHub repository.

Start integrating Font Awesome icons seamlessly into your Android applications with the Fontawesome Android Library and elevate your app’s user experience to the next level!

Leave a Reply

Your email address will not be published. Required fields are marked *