You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+61-3Lines changed: 61 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Material Icon Library
2
2
3
-
A library containing over 1000 material vector icons that can be easily used as Drawable or as a standalone View. 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.
3
+
A library containing over 1000 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.
4
4
5
5
# Demo
6
6
@@ -13,6 +13,7 @@ A library containing over 1000 material vector icons that can be easily used as
13
13
- Currently contains 1457 icons, you can look at them here: https://materialdesignicons.com
14
14
- Configured in less than a minute
15
15
- Adds about 200kb to your apk (so a wopping average of __170 bytes per icon__)
16
+
- Includes a custom Drawable, IconView and a MenuInflater for all different icon use cases
16
17
17
18
# Usage
18
19
@@ -24,19 +25,23 @@ Get the font file [__here__](https://github.com/code-mc/material-icon-lib/blob/m
24
25
25
26
You 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!
26
27
28
+
Previews work inside layout files, menu resource files sadly do not support previews (more on those below).
29
+
27
30
## Step 1
28
31
29
32
#### Gradle
30
33
31
34
```groovy
32
35
dependencies {
33
-
compile 'net.steamcrafted:materialiconlib:1.0.9'
36
+
compile 'net.steamcrafted:materialiconlib:1.1.0'
34
37
}
35
38
```
36
39
37
40
## Step 2
38
41
39
-
You now have the choice of using the provided `MaterialIconView` or just your preferred ImageView and use the `MaterialDrawable` as Drawable resource. Let's first go over the provided view:
42
+
There's a total of 3 different use cases. 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.
That 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.
122
129
123
130
The initialisation happens using the `MaterialDrawableBuilder`, which you can use to set all the properties of the drawable:
@@ -182,6 +189,57 @@ builder.getOpacity();
182
189
builder.setStyle(Paint.Style style);
183
190
```
184
191
192
+
### MaterialMenuInflater
193
+
194
+
With 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:
xmlns:app="http://schemas.android.com/apk/res-auto" <!-- important, you'll have to include this to use the custom xml attributes -->
199
+
xmlns:tools="http://schemas.android.com/tools" >
200
+
201
+
<!-- example of a menu item with an icon -->
202
+
<item
203
+
android:title="Disable Wifi"
204
+
app:showAsAction="always"
205
+
app:materialIcon="wifi_off" <!-- This sets the icon, HAS AUTOCOMPLETE ;) -->
206
+
app:materialIconColor="#FE0000" <!-- Sets the icon color -->
207
+
/>
208
+
209
+
</menu>
210
+
```
211
+
212
+
To 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`:
213
+
214
+
```java
215
+
@Override
216
+
public boolean onCreateOptionsMenu(Menu menu) {
217
+
MaterialMenuInflater
218
+
.with(this) // Provide the activity context
219
+
// Set the fall-back color for all the icons. Colors set inside the XML will always have higher priority
220
+
.setDefaultColor(Color.BLUE)
221
+
// Inflate the menu
222
+
.inflate(R.menu.your_menu_resource, menu);
223
+
return true;
224
+
}
225
+
```
226
+
227
+
Since 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:
0 commit comments