Import material design icons into an android project

IconsMaterial Design

Icons Problem Overview


Is there an easy way to import all the icons of the Material Design icons repository into an android project with out the hazard of doing it manually?

Icons Solutions


Solution 1 - Icons

Take a look at Vector Asset Studio

> Follow these steps to start Vector Asset Studio: > > - 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: > > - Select "Material Icon" (by clicking on the Clip Art: ICON) > - Click Choose > - Select a material icon

Solution 2 - Icons

On folder drawable > right click > new > vector asset, then click the icon:

Android Studio screen shots showing non-obvious place where to click

Solution 3 - Icons

You can use this new plugin for android studio Android Material Design Icon Generator Plugin to help you work with these material icons provided by Google : Google material-design-icons

Solution 4 - Icons

Here is a script that clones the github repository of the material design icons at

https://github.com/google/material-design-icons

and creates an index of all files. It also copies the svg files to subdirectories by category. You can use this as a basis to copy the files your are interested in into your project - just modify the find and cp copy statement to your liking. If you e.g. need the png's at a certain size - they are in neighbouring directories and you need to modify the find and copy command accordingly then.

enter image description here

#!/bin/bash
# WF 2016-06-04
# get google material design icons
# see http://stackoverflow.com/questions/28684759/import-material-design-icons-into-an-android-project
tmp=/tmp/icons
index=$tmp/index.html
mkdir -p $tmp
cd $tmp
if [ ! -d material-design-icons ]
then
  git clone https://github.com/google/material-design-icons
fi
cat << EOF > $index
<html>
  <head>
	<head>
	<body>
	  <h1>Google Material Design Icons</h1>
EOF
for icon in `find . -name *.svg | grep production | grep 48`
do
	svg=`basename $icon .svg`
	category=`echo $icon | cut -f3 -d '/'`
	echo $category $svg.svg
	mkdir -p $tmp/$category
    cp $icon $tmp/$category
	echo "    <img src='"$icon"' title='"$category $svg"' >" >> $index
done
cat << EOF >> $index
  </body>
</html>
EOF

Solution 5 - Icons

I found this link helpful for me.

https://dev.materialdesignicons.com/getting-started/android

gradle implementation is available

dependencies {
    implementation 'net.steamcrafted:materialiconlib:1.1.5'
}

After adding gradle dependency, you can create menu item this way.

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto" <!-- important, you'll have to include this to use the custom xml attributes -->
    xmlns:tools="http://schemas.android.com/tools" >

    <!-- example of a menu item with an icon -->
    <item
        android:title="Disable Wifi"
        app:showAsAction="always"
        app:materialIcon="wifi_off" <!-- This sets the icon, HAS AUTOCOMPLETE ;) -->
        app:materialIconColor="#FE0000" <!-- Sets the icon color -->
    />

</menu>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionIvan AranibarView Question on Stackoverflow
Solution 1 - IconsmpkuthView Answer on Stackoverflow
Solution 2 - IconsDaleView Answer on Stackoverflow
Solution 3 - IconsOussama Haff.View Answer on Stackoverflow
Solution 4 - IconsWolfgang FahlView Answer on Stackoverflow
Solution 5 - IconsNaveed JamaliView Answer on Stackoverflow