Skip to content

Commit 9c2af7b

Browse files
committed
updated readme for 1.1.0
1 parent 6c86f31 commit 9c2af7b

File tree

3 files changed

+63
-5
lines changed

3 files changed

+63
-5
lines changed

README.md

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Material Icon Library
22

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.
44

55
# Demo
66

@@ -13,6 +13,7 @@ A library containing over 1000 material vector icons that can be easily used as
1313
- Currently contains 1457 icons, you can look at them here: https://materialdesignicons.com
1414
- Configured in less than a minute
1515
- 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
1617

1718
# Usage
1819

@@ -24,19 +25,23 @@ Get the font file [__here__](https://github.com/code-mc/material-icon-lib/blob/m
2425

2526
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!
2627

28+
Previews work inside layout files, menu resource files sadly do not support previews (more on those below).
29+
2730
## Step 1
2831

2932
#### Gradle
3033

3134
```groovy
3235
dependencies {
33-
compile 'net.steamcrafted:materialiconlib:1.0.9'
36+
compile 'net.steamcrafted:materialiconlib:1.1.0'
3437
}
3538
```
3639

3740
## Step 2
3841

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.
43+
44+
### MaterialIconView
4045

4146
Add the view to your XML:
4247

@@ -118,6 +123,8 @@ yourMaterialIconView.setScaleType(ScaleType.CENTER)
118123
// etc...
119124
```
120125

126+
### MaterialDrawable
127+
121128
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.
122129

123130
The initialisation happens using the `MaterialDrawableBuilder`, which you can use to set all the properties of the drawable:
@@ -182,6 +189,57 @@ builder.getOpacity();
182189
builder.setStyle(Paint.Style style);
183190
```
184191

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:
195+
196+
```xml
197+
<menu xmlns:android="http://schemas.android.com/apk/res/android"
198+
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:
228+
229+
```java
230+
// Get the toolbar from layout
231+
Toolbar toolbar = (Toolbar) findViewById(R.id.your_toolbar);
232+
233+
MaterialMenuInflater
234+
.with(this) // Provide a context, activity context will do just fine
235+
// Set the fall-back color for all the icons. Colors set inside the XML will always have higher priority
236+
.setDefaultColor(Color.BLUE)
237+
// Inflate the menu
238+
.inflate(R.menu.your_menu_resource, toolbar.getMenu());
239+
```
240+
241+
And that's all there is to it.
242+
185243
#License
186244
187245
Released under the [Apache 2.0 License](https://github.com/code-mc/material-icon-lib/blob/master/license.md)

app/src/main/res/menu/menu_main.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<menu xmlns:android="http://schemas.android.com/apk/res/android"
22
xmlns:app="http://schemas.android.com/apk/res-auto"
33
xmlns:tools="http://schemas.android.com/tools" >
4-
<item app:showAsAction="always" android:title="a" app:materialIcon="numeric_0_box" app:materialIconColor="#FE0000"/>
4+
<item app:showAsAction="always" android:title="a" app:materialIcon="wifi_off" app:materialIconColor="#FE0000"/>
55
<item app:showAsAction="always" android:title="a" app:materialIcon="numeric_1_box" app:materialIconColor="#FF9C00"/>
66
<item app:showAsAction="always" android:title="a" app:materialIcon="numeric_2_box" app:materialIconColor="#F5FF00"/>
77
<item app:showAsAction="always" android:title="a" app:materialIcon="numeric_3_box" app:materialIconColor="#3CF10E"/>

materialiconlib/src/main/java/net/steamcrafted/materialiconlib/MaterialDrawableBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static MaterialDrawableBuilder with(Context context){
6767
return new MaterialDrawableBuilder(context);
6868
}
6969

70-
public MaterialDrawable build() throws IconNotSetException{
70+
public Drawable build() throws IconNotSetException{
7171
if(icon == null){
7272
throw new IconNotSetException();
7373
}

0 commit comments

Comments
 (0)