Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use the Material Design icons in XML in Android?

I managed to clone the git repository of Material Design icons, but now I'm struggling with how to use it.

I want to use the icon resources in the XML files, in the XML attributes like android:icon="@drawable/***.

so I searched quite many articles and none of them seems to be clear so far. Can someone explain?

like image 825
MarshallLee Avatar asked Nov 21 '15 23:11

MarshallLee


People also ask

Can I use material design icons?

The complete set of material icons are available on the material icon library. The icons are available for download in SVG or PNGs, formats that are suitable for web, Android, and iOS projects or for inclusion in any designer tools.

How do you use material icons?

Google's Material Icons provides a long list of icons. Choose any one of them and add the name of the icon class to any HTML element within the < body > tag. In the following example, we have used the icon named accessibility that belongs to the action category.

How to add material icons to an Android app?

In Android Studio, open an Android app project. In the Project window, select the Android view. Right-click the res folder and select New > Vector Asset. After you open Vector Asset Studio, you can add a material icon as follows:

How to use material design components in an Android app?

This example demonstrates how to use Material Design components in an Android App. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to src/MainActivity.java

How to add icons to material design buttons in Material Design?

Click on the marked button in the below image, to select the desired vector icons. By adding the app:icon attribute in each of the buttons and selecting the desired vector icon from the drawable folder, will add the icon to the material design buttons. So, invoke the following code. Here the icons are optional.

Where can I find custom icons suitable for Android devices?

PNGs suitable for Android are available from the material icons library. These come in all the supported screen densities so they should look good on any device. The icons are also available in the material design icons git repository in the same combination of colors and sizes named as follows:


1 Answers

You don't need to clone the repository to do this. If you're using an up to date version of Android Studio you can import the individual icons you need directly.

Right-click on your drawable folder and in the menu go to New > Vector Asset. From there the default option is to select any of the Material icons to use, or you have the option to use your own SVG files.

like image 129
Lewis McGeary Avatar answered Sep 19 '22 15:09

Lewis McGeary