{"id":13395973,"url":"https://github.com/code-mc/material-icon-lib","last_synced_at":"2025-05-15T21:00:21.551Z","repository":{"id":35129084,"uuid":"39332505","full_name":"code-mc/material-icon-lib","owner":"code-mc","description":"Library containing over 2000 material vector icons that can be easily used as Drawable or as a standalone View.","archived":false,"fork":false,"pushed_at":"2019-12-15T20:49:51.000Z","size":1351,"stargazers_count":2271,"open_issues_count":12,"forks_count":215,"subscribers_count":61,"default_branch":"master","last_synced_at":"2025-04-01T01:41:38.323Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"rowanj/gitx","license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/code-mc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"license.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-19T12:10:11.000Z","updated_at":"2025-03-25T13:29:55.000Z","dependencies_parsed_at":"2022-09-16T10:00:16.525Z","dependency_job_id":null,"html_url":"https://github.com/code-mc/material-icon-lib","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-mc%2Fmaterial-icon-lib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-mc%2Fmaterial-icon-lib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-mc%2Fmaterial-icon-lib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-mc%2Fmaterial-icon-lib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/code-mc","download_url":"https://codeload.github.com/code-mc/material-icon-lib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247767232,"owners_count":20992538,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T18:00:36.708Z","updated_at":"2025-04-08T02:41:50.357Z","avatar_url":"https://github.com/code-mc.png","language":"Java","readme":"# Material Icon Library\n\nA library containing over 2000 material vector icons that can be easily used as Drawable, a standalone View or inside menu resource files. Tired of having to search for and generate png resources every time you want to test something? This library puts an end to that burden and makes swapping icons a breeze, check out the usage below and you'll see why.\n\n# Demo\n\n![](http://i.imgur.com/KXHfXo8.gif)\n\n# Stats\n\n - MinSdk 4\n - LIVE previews and code completion in the Android Studio Designer (Does NOT work out of the box, see step 0 below!)\n - Currently contains 2354 icons, you can look at them here: https://materialdesignicons.com\n - Configured in less than a minute\n - Adds about 257kb to your apk (so a whopping average of __109 bytes per icon__)\n - Includes a custom Drawable, IconView and a MenuInflater for all different icon use cases\n\n# Usage\n\n## Step 0\n\nNow I still have your attention, to get the previews to work in Android Studio you'll have to put the font file inside the assets of your project yourself. Due to a bug it does not think about looking inside the library's assets for some odd reason.\n\nGet the font file [__here__](https://github.com/code-mc/material-icon-lib/blob/master/materialiconlib/src/main/assets/materialdesignicons-webfont.ttf?raw=true).\n\nYou don't have to worry about android including the file twice in your apk. Android Studio recognizes the duplicate file name and only keeps one copy in your apk!\n\nPreviews work inside layout files, menu resource files sadly do not support previews (more on those below).\n\n## Step 1\n\n#### Gradle\n\n```groovy\ndependencies {\n    compile 'net.steamcrafted:materialiconlib:1.1.5'\n}\n```\n\n## Step 2\n\nThere's a total of 3 different use cases (click the links to jump to their section). You can use the provided [`MaterialIconView`](#materialiconview) which mostly is just a more advanced `ImageView` or use your preferred `ImageView` and use the [`MaterialDrawable`](#materialdrawable) as Drawable resource. If you want to spice up your `Toolbar` with icons from this library there is a custom [`MaterialMenuInflater`](#materialmenuinflater) that does just that in a single line of code.\n\n### MaterialIconView\n\nAdd the view to your XML:\n\n```xml\n\u003cnet.steamcrafted.materialiconlib.MaterialIconView\n    xmlns:app=\"http://schemas.android.com/apk/res-auto\" \u003c!-- VERY IMPORTANT --\u003e\n\n    android:layout_width=\"48dp\"\n    android:layout_height=\"48dp\"\n    app:materialIcon=\"clipboard_arrow_down\" \u003c!-- This sets the icon, HAS AUTOCOMPLETE ;) --\u003e\n    app:materialIconColor=\"#fff\" \u003c!-- Sets the icon color --\u003e\n    app:materialIconSize=\"24dp\"  \u003c!-- Sets the icon size --\u003e\n    android:scaleType=\"center\" \u003c!-- Centers the icon (all scale types supported) --\u003e\n    android:background=\"@android:color/darker_gray\"\n    android:id=\"@+id/icon\"\n/\u003e\n```\n\nYou can also use the other route: the \"wrap_content\" way:\n\n```xml\n\u003cnet.steamcrafted.materialiconlib.MaterialIconView\n    xmlns:app=\"http://schemas.android.com/apk/res-auto\" \u003c!-- VERY IMPORTANT --\u003e\n\n    android:layout_width=\"wrap_content\"\n    android:layout_height=\"wrap_content\"\n    android:padding=\"12dp\" \u003c!-- now we use a padding to center the icon --\u003e\n    app:materialIcon=\"clipboard_arrow_down\" \u003c!-- This sets the icon, HAS AUTOCOMPLETE ;) --\u003e\n    app:materialIconColor=\"#fff\" \u003c!-- Sets the icon color --\u003e\n    app:materialIconSize=\"24dp\"  \u003c!-- Sets the icon size --\u003e\n    \u003c!-- scaleType is no longer required for this method --\u003e\n    android:background=\"@android:color/darker_gray\"\n    android:id=\"@+id/icon\"\n/\u003e\n```\n\nThe view is inherited from `ImageView`. This means that you can use any and all features of the very flexible `ImageView` BUT be reminded that this view does not cache any of the drawables it creates, so every time you change something about the icon, it's going to regenerate the drawable. Using this view inside listviews is highly discouraged, if you want to use these icons in a `ListView`, cache the drawables and use the `MaterialDrawableBuilder` in combination with an `ImageView`!\n\nAs mentioned before this extends the android `ImageView` class, there's a few methods unique to this particular view:\n\n```java\n// Sets the icon, all 1000+ icons are available inside the MaterialDrawableBuilder.IconValue enum\nyourMaterialIconView.setIcon(IconValue iconValue);\n\n// Sets the size of the icon to the default action bar icon size\nyourMaterialIconView.setToActionbarSize();\n\n// Provide a dimension resource to use as icon size\nyourMaterialIconView.setSizeResource(int dimenRes);\n\n// Set the icon size using a value in dp units\nyourMaterialIconView.setSizeDp(int size);\n\n// Set the icon size using a pixel value\nyourMaterialIconView.setSizePx(int size);\n\n// Set the icon color\nyourMaterialIconView.setColor(int color);\n\n// Set the icon color using a color resource\nyourMaterialIconView.setColorResource(int colorRes);\n\n// Set the icon's alpha value (0-255) 0 for completely transparent\nyourMaterialIconView.setAlpha(int alpha);\n\n// Sets a custom colorfilter to the drawing paint (for the more advanced devs)\nyourMaterialIconView.setColorFilter(ColorFilter cf);\n\n// Clear the color filter set using above method\nyourMaterialIconView.clearColorFilter();\n\n// Sets a custom paint style (for the more advanced devs)\nyourMaterialIconView.setStyle(Paint.Style style);\n\n\n// You can use any of the ImageView methods as well:\nyourMaterialIconView.setBackgroundColor(Color.WHITE)\nyourMaterialIconView.setScaleType(ScaleType.CENTER)\n// etc...\n```\n\n### MaterialDrawable\n\nThat was easy, right? Next up the custom drawables, they are internally used by the `MaterialIconView` so you'll see that they share many of the same methods.\n\nThe initialisation happens using the `MaterialDrawableBuilder`, which you can use to set all the properties of the drawable:\n\n```java\n// The method returns a MaterialDrawable, but as it is private to the builder you'll have to store it as a regular Drawable ;)\nDrawable yourDrawable = MaterialDrawableBuilder.with(context) // provide a context\n        .setIcon(MaterialDrawableBuilder.IconValue.WEATHER_RAINY) // provide an icon\n        .setColor(Color.WHITE) // set the icon color\n        .setToActionbarSize() // set the icon size\n    .build(); // Finally call build\n```\n\nThis will throw an `IconNotSetException` if you forget to provide an icon.\n\nOnce you call build, your Drawable will be spit out and you are ready to use it everywhere you please! Setting it to a view is just as easy as with any other `Drawable` (e.g. for `ImageView`):\n\n```java\nyourImageView.setImageDrawable(yourDrawable);\n```\n\nAnd that's all there is to it. Below are all the methods you can use with the `MaterialDrawableBuilder` for reference.\n\n```java\n// Sets the icon, all 1000+ icons are available inside the MaterialDrawableBuilder.IconValue enum\nbuilder.setIcon(IconValue iconValue);\n\n// Builds the drawable, this method always comes last ofcourse\nbuilder.build();\n\n// Sets the size of the icon to the default action bar icon size\nbuilder.setToActionbarSize();\n\n// Provide a dimension resource to use as icon size\nbuilder.setSizeResource(int dimenRes);\n\n// Set the icon size using a value in dp units\nbuilder.setSizeDp(int size);\n\n// Set the icon size using a pixel value\nbuilder.setSizePx(int size);\n\n// Set the icon color\nbuilder.setColor(int color);\n\n// Set the icon color using a color resource\nbuilder.setColorResource(int colorRes);\n\n// Set the icon's alpha value (0-255) 0 for completely transparent\nbuilder.setAlpha(int alpha);\n\n// Sets a custom colorfilter to the drawing paint (for the more advanced devs)\nbuilder.setColorFilter(ColorFilter cf);\n\n// Clear the color filter set using above method\nbuilder.clearColorFilter();\n\n// Returns the alpha value\nbuilder.getOpacity();\n\n// Sets a custom paint style (for the more advanced devs)\nbuilder.setStyle(Paint.Style style);\n```\n\n### MaterialMenuInflater\n\nWith the `MaterialMenuInflater` you can use any of the icons available in this library *inside* your menu resource files. In XML you'd have to do the following:\n\n```xml\n\u003cmenu xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    xmlns:app=\"http://schemas.android.com/apk/res-auto\" \u003c!-- important, you'll have to include this to use the custom xml attributes --\u003e\n    xmlns:tools=\"http://schemas.android.com/tools\" \u003e\n\n    \u003c!-- example of a menu item with an icon --\u003e\n    \u003citem\n        android:title=\"Disable Wifi\"\n        app:showAsAction=\"always\"\n        app:materialIcon=\"wifi_off\" \u003c!-- This sets the icon, HAS AUTOCOMPLETE ;) --\u003e\n        app:materialIconColor=\"#FE0000\" \u003c!-- Sets the icon color --\u003e\n    /\u003e\n\n\u003c/menu\u003e\n```\n\nTo actually inflate this menu you'll now have to use the `MaterialMenuInflater` instead of the default one. For the AppCompatActivity do the following in your `onCreateOptionsMenu`:\n\n```java\n@Override\npublic boolean onCreateOptionsMenu(Menu menu) {\n    MaterialMenuInflater\n            .with(this) // Provide the activity context\n            // Set the fall-back color for all the icons. Colors set inside the XML will always have higher priority\n            .setDefaultColor(Color.BLUE)\n            // Inflate the menu\n            .inflate(R.menu.your_menu_resource, menu);\n    return true;\n}\n```\n\nSince the release of the Appcompat-v7 library you can also use the `Toolbar` view inside your XML layouts. Inflating a menu for a toolbar is a bit different from the usual way, but it is just as easy:\n\n```java\n// Get the toolbar from layout\nToolbar toolbar = (Toolbar) findViewById(R.id.your_toolbar);\n\nMaterialMenuInflater\n        .with(this) // Provide a context, activity context will do just fine\n        // Set the fall-back color for all the icons. Colors set inside the XML will always have higher priority\n        .setDefaultColor(Color.BLUE)\n        // Inflate the menu\n        .inflate(R.menu.your_menu_resource, toolbar.getMenu());\n```\n\nAnd that's all there is to it.\n\n# License\n\nReleased under the [Apache 2.0 License](https://github.com/code-mc/material-icon-lib/blob/master/license.md)\n\n* __MaterialDesignicons__ Released under the [SIL Open Font License 1.1](http://opensource.org/licenses/OFL-1.1)\n* __Google Material Design Icons__ Released under the [Apache 2.0 License](https://github.com/google/material-design-icons/blob/master/LICENSE)\n","funding_links":[],"categories":["Index `(light-weight pages)`","Java","图标","Index"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcode-mc%2Fmaterial-icon-lib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcode-mc%2Fmaterial-icon-lib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcode-mc%2Fmaterial-icon-lib/lists"}