Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.

Android_Adding New Icons

Miroslav Smukov edited this page Jun 19, 2016 · 9 revisions

Adding New Icons

It's to improve our UI further by changing the icons used throughout the app. In this post we'll change the icons in the Navigation Drawer menu, and in our FAB (Floating Action Button).

Material Icons

Material icons are designed by Google. They are intended to be simple, and easy to use in web, Android, and iOS projects. They are created using Google's design guidelines to depict in simple and minimal forms the universal concepts used commonly throughout a UI. We are going to be using these icons in our project.

Adding Material Icons to Project

In Android Studio, there's a feature called Vector Asset Studio that we are going to use to easily import new icons.

To access Vector Asset Studio, open your project in Android Studio, and right click on the res folder. Select New > Vector Asset and the Vector Asset Studio will open. Now select Material Icon and click on Choose. You will now be presented with a list of available icons. Choose one icon and click OK > Next > Finish. A new icon will be added to your project's drawable folder, and it's ready to be used.

Changing the Menu icons

Below you can see the sample code on how I changed the Navigation Drawer icons to use the new icons I imported using Vector Asset Studio.

Source Code

    <group
        android:id="@+id/menu_top"
        android:checkableBehavior="single">
        <item
            android:checked="true"
            android:id="@+id/nav_my_profile"
            android:icon="@drawable/ic_person_black_24dp"
            android:title="My Profile" />
        <item
            android:id="@+id/nav_contacts"
            android:icon="@drawable/ic_people_black_24dp"
            android:title="My Contacts" />
    </group>

    <group
        android:id="@+id/menu_bottom"
        android:checkableBehavior="single">
        <item
            android:id="@+id/nav_settings"
            android:icon="@drawable/ic_settings_black_24dp"
            android:title="Settings" />
        <item
            android:id="@+id/nav_send_feedback"
            android:icon="@drawable/ic_menu_send"
            android:title="Send Feedback" />
    </group>

Changing the Icon Color

All the icons that you can import are black, but you shouldn't be worried. All you need to do to change the color is use the android:tint attribute on the element that's using the icon. Below you can see how I changed the color of the icon on my FloatingActionButton:

Source Code

 android:src="@drawable/ic_create_black_24dp"
 android:tint="@color/colorBackground"

Conclusion

Google has really helped us by providing ready made set of icons that we can use in our Android application. Importing and using the icons couldn't be simpler. Below are the end result of the changes I made to the app:

New Icons

References

Clone this wiki locally