Coder Social home page Coder Social logo

material-icon-lib's Introduction

Material Icon Library

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

Demo

Stats

  • MinSdk 4
  • LIVE previews and code completion in the Android Studio Designer (Does NOT work out of the box, see step 0 below!)
  • Currently contains 2354 icons, you can look at them here: https://materialdesignicons.com
  • Configured in less than a minute
  • Adds about 257kb to your apk (so a whopping average of 109 bytes per icon)
  • Includes a custom Drawable, IconView and a MenuInflater for all different icon use cases

Usage

Step 0

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

Get the font file here.

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!

Previews work inside layout files, menu resource files sadly do not support previews (more on those below).

Step 1

Gradle

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

Step 2

There's a total of 3 different use cases (click the links to jump to their section). You can use the provided MaterialIconView which mostly is just a more advanced ImageView or use your preferred ImageView and use the MaterialDrawable as Drawable resource. If you want to spice up your Toolbar with icons from this library there is a custom MaterialMenuInflater that does just that in a single line of code.

MaterialIconView

Add the view to your XML:

<net.steamcrafted.materialiconlib.MaterialIconView
    xmlns:app="http://schemas.android.com/apk/res-auto" <!-- VERY IMPORTANT -->

    android:layout_width="48dp"
    android:layout_height="48dp"
    app:materialIcon="clipboard_arrow_down" <!-- This sets the icon, HAS AUTOCOMPLETE ;) -->
    app:materialIconColor="#fff" <!-- Sets the icon color -->
    app:materialIconSize="24dp"  <!-- Sets the icon size -->
    android:scaleType="center" <!-- Centers the icon (all scale types supported) -->
    android:background="@android:color/darker_gray"
    android:id="@+id/icon"
/>

You can also use the other route: the "wrap_content" way:

<net.steamcrafted.materialiconlib.MaterialIconView
    xmlns:app="http://schemas.android.com/apk/res-auto" <!-- VERY IMPORTANT -->

    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="12dp" <!-- now we use a padding to center the icon -->
    app:materialIcon="clipboard_arrow_down" <!-- This sets the icon, HAS AUTOCOMPLETE ;) -->
    app:materialIconColor="#fff" <!-- Sets the icon color -->
    app:materialIconSize="24dp"  <!-- Sets the icon size -->
    <!-- scaleType is no longer required for this method -->
    android:background="@android:color/darker_gray"
    android:id="@+id/icon"
/>

The 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!

As mentioned before this extends the android ImageView class, there's a few methods unique to this particular view:

// Sets the icon, all 1000+ icons are available inside the MaterialDrawableBuilder.IconValue enum
yourMaterialIconView.setIcon(IconValue iconValue);

// Sets the size of the icon to the default action bar icon size
yourMaterialIconView.setToActionbarSize();

// Provide a dimension resource to use as icon size
yourMaterialIconView.setSizeResource(int dimenRes);

// Set the icon size using a value in dp units
yourMaterialIconView.setSizeDp(int size);

// Set the icon size using a pixel value
yourMaterialIconView.setSizePx(int size);

// Set the icon color
yourMaterialIconView.setColor(int color);

// Set the icon color using a color resource
yourMaterialIconView.setColorResource(int colorRes);

// Set the icon's alpha value (0-255) 0 for completely transparent
yourMaterialIconView.setAlpha(int alpha);

// Sets a custom colorfilter to the drawing paint (for the more advanced devs)
yourMaterialIconView.setColorFilter(ColorFilter cf);

// Clear the color filter set using above method
yourMaterialIconView.clearColorFilter();

// Sets a custom paint style (for the more advanced devs)
yourMaterialIconView.setStyle(Paint.Style style);


// You can use any of the ImageView methods as well:
yourMaterialIconView.setBackgroundColor(Color.WHITE)
yourMaterialIconView.setScaleType(ScaleType.CENTER)
// etc...

MaterialDrawable

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.

The initialisation happens using the MaterialDrawableBuilder, which you can use to set all the properties of the drawable:

// The method returns a MaterialDrawable, but as it is private to the builder you'll have to store it as a regular Drawable ;)
Drawable yourDrawable = MaterialDrawableBuilder.with(context) // provide a context
        .setIcon(MaterialDrawableBuilder.IconValue.WEATHER_RAINY) // provide an icon
        .setColor(Color.WHITE) // set the icon color
        .setToActionbarSize() // set the icon size
    .build(); // Finally call build

This will throw an IconNotSetException if you forget to provide an icon.

Once 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):

yourImageView.setImageDrawable(yourDrawable);

And that's all there is to it. Below are all the methods you can use with the MaterialDrawableBuilder for reference.

// Sets the icon, all 1000+ icons are available inside the MaterialDrawableBuilder.IconValue enum
builder.setIcon(IconValue iconValue);

// Builds the drawable, this method always comes last ofcourse
builder.build();

// Sets the size of the icon to the default action bar icon size
builder.setToActionbarSize();

// Provide a dimension resource to use as icon size
builder.setSizeResource(int dimenRes);

// Set the icon size using a value in dp units
builder.setSizeDp(int size);

// Set the icon size using a pixel value
builder.setSizePx(int size);

// Set the icon color
builder.setColor(int color);

// Set the icon color using a color resource
builder.setColorResource(int colorRes);

// Set the icon's alpha value (0-255) 0 for completely transparent
builder.setAlpha(int alpha);

// Sets a custom colorfilter to the drawing paint (for the more advanced devs)
builder.setColorFilter(ColorFilter cf);

// Clear the color filter set using above method
builder.clearColorFilter();

// Returns the alpha value
builder.getOpacity();

// Sets a custom paint style (for the more advanced devs)
builder.setStyle(Paint.Style style);

MaterialMenuInflater

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:

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

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:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MaterialMenuInflater
            .with(this) // Provide the activity context
            // Set the fall-back color for all the icons. Colors set inside the XML will always have higher priority
            .setDefaultColor(Color.BLUE)
            // Inflate the menu
            .inflate(R.menu.your_menu_resource, menu);
    return true;
}

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:

// Get the toolbar from layout
Toolbar toolbar = (Toolbar) findViewById(R.id.your_toolbar);

MaterialMenuInflater
        .with(this) // Provide a context, activity context will do just fine
        // Set the fall-back color for all the icons. Colors set inside the XML will always have higher priority
        .setDefaultColor(Color.BLUE)
        // Inflate the menu
        .inflate(R.menu.your_menu_resource, toolbar.getMenu());

And that's all there is to it.

License

Released under the Apache 2.0 License

material-icon-lib's People

Contributors

code-mc avatar kasijjuf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

material-icon-lib's Issues

Android studio gradle build not working

I am trying to use your library in project. But I am getting error when i add
compile 'net.steamcrafted:materialiconlib:1.0.3' in build.gradle

Error getting:

Error:(33, 13) Failed to resolve: net.steamcrafted:materialiconlib:1.0.3

Add documentation about Toolbar menu

It seems that this library has a partial support for actionbar (builder.setToActionbarSize();). Can we use it the Toolbar component?

Toolbar icons are defined in resources/menu as following:

<item
    android:id="@+id/menu_refresh"
    android:icon="@drawable/ic_action_navigation_refresh"
    app:showAsAction="ifRoom"
    android:title="@string/menu_refresh"/>

So we cannot blindly replace it with the <net.steamcrafted.materialiconlib.MaterialIconView /> tag. Is there any way to do it in another way?

Wrong images after 1.1.4

After 1.1.4 (so 1.1.4 and 1.1.5) most icons are making no sense to begin with..

Instead of lock, i see a flower. Instead of PDF i see something not related, etc.

Will this ever be fixed?

Some of the icons which do not have alias unable to use on android

Hi, This is an awesome library. I am using it in the android studio. I have found that some of the icons which are listed on search are not available on the android studio. When I dig more found the icon which doesn't have an alias is not coming. I want to know how to use that icon in the android studio.

API 16 crash. Need help

Hi, I have a crash when run on device support api 16. I checked closed issue #32 but it isn't helpful
It can be an error when inflating some class. Can you show me the solution to deal with it. Thanks you.

The error is:
05-20 15:32:39.929 8920-8920/vn.gofime.gofime E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{vn.gofime.gofime/vn.gofime.gofime.pagemainmap}: android.view.InflateException: Binary XML file line #0: Error inflating class net.steamcrafted.materialiconlib.MaterialIconView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class net.steamcrafted.materialiconlib.MaterialIconView
at android.view.LayoutInflater.createView(LayoutInflater.java:613)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at vn.gofime.gofime.pagemainmap.onCreate(pagemainmap.java:355)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 
at android.app.ActivityThread.access$600(ActivityThread.java:130) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:137) 
at android.app.ActivityThread.main(ActivityThread.java:4745) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:511) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:587)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:749) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
at vn.gofime.gofime.pagemainmap.onCreate(pagemainmap.java:355) 
at android.app.Activity.performCreate(Activity.java:5008) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 
at android.app.ActivityThread.access$600(ActivityThread.java:130) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:137) 
at android.app.ActivityThread.main(ActivityThread.java:4745) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:511) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f08005d a=-1 r=0x7f08005d}
at android.content.res.Resources.loadDrawable(Resources.java:1897)
at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
at android.view.View.(View.java:3336)
at android.widget.ImageView.(ImageView.java:114)
at android.widget.ImageView.(ImageView.java:110)
at net.steamcrafted.materialiconlib.MaterialIconView.(MaterialIconView.java:30)
at java.lang.reflect.Constructor.constructNative(Native Method) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:417) 
at android.view.LayoutInflater.createView(LayoutInflater.java:587) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:749) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
at vn.gofime.gofime.pagemainmap.onCreate(pagemainmap.java:355) 
at android.app.Activity.performCreate(Activity.java:5008) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 
at android.app.ActivityThread.access$600(ActivityThread.java:130) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:137) 
at android.app.ActivityThread.main(ActivityThread.java:4745) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:511) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
at dalvik.system.NativeStart.main(Native Method) 

setAlpha / getOpacity

setAlpha and getOpacity methods can be misleading.

Alpha is usually an integer between 0-255 (as it is for setAlpha), while opacity is a float from 0 to 1. What value do we retrieve when we call getOpacity?

I think you should create a getAlpha method and set getOpacity as deprecated for better understanding on this point.

Awesome project though!

Update frequency

I assume that this lib is going to get updated with new icons from the community @ materialdesignicons.com. I'd like to know how often.

Thanks for the lib, it's very useful :)

Using MaterialIconView in clickable parent makes ripple lag

When using MaterialIconView in a clickable parent (a ListView for example), the ripple effect happening when clicking the parent lags and seems to contain artifacts.

The ListView has only one element. Tried on a OnePlusOne with no application in the background (so lag isn't because of a heavy work happening in the background).

Using standard ImageView or ImageButton component works well.

Some icons and code completion is not working

When I set app:materialIcon="pen", it's OK.
But when I set app:materialIcon="calendar-text", I get error like this.

Error:(62, 35) String types not allowed (at 'materialIcon' with value 'calendar-text').

PS: Autocomplete is not work. And I put the font file inside the assets already.

Asset not found

this error
Asset not found: materialdesignicons-webfont.ttf

MaterialDrawableBuilder does not care about Drawable.setBounds

Hey,

the drawable created from the MaterialDrawableBuilder does not support the Drawable.setBounds, for example when used in custom views...

as workaround i had to create a new drawable for each size change and move the object with translate, which is not very optimal...

support SVG

Is possible support load separate SVG file

MaterialIconColor with alpha channel

Please, add support for transparent colors for icons. Right now it ignores alpha channel and fill icon with black (for #1f000000 for example)

Crash on API level 19 and below

Unable to solve this and not sure why this happens.
Here is my stack trace:

Exception java.lang.RuntimeException: Unable to start activity ComponentInfo{com.chalkstreet.app/com.chalkstreet.app.home.HomeActivity}: android.view.InflateException: Binary XML file line #385: Error inflating class net.steamcrafted.materialiconlib.MaterialIconView
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2338)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2390)
android.app.ActivityThread.access$800 (ActivityThread.java:151)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1321)
android.os.Handler.dispatchMessage (Handler.java:110)
android.os.Looper.loop (Looper.java:193)
android.app.ActivityThread.main (ActivityThread.java:5292)
java.lang.reflect.Method.invokeNative (Method.java)
java.lang.reflect.Method.invoke (Method.java:515)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:824)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:640)
dalvik.system.NativeStart.main (NativeStart.java)
arrow_drop_down
Caused by android.view.InflateException: Binary XML file line #385: Error inflating class net.steamcrafted.materialiconlib.MaterialIconView
android.view.LayoutInflater.createView (LayoutInflater.java:620)
android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:696)
android.view.LayoutInflater.rInflate (LayoutInflater.java:755)
android.view.LayoutInflater.rInflate (LayoutInflater.java:758)
android.view.LayoutInflater.rInflate (LayoutInflater.java:758)
android.view.LayoutInflater.parseInclude (LayoutInflater.java:839)
android.view.LayoutInflater.rInflate (LayoutInflater.java:745)
android.view.LayoutInflater.inflate (LayoutInflater.java:492)
android.view.LayoutInflater.inflate (LayoutInflater.java:397)
android.view.LayoutInflater.inflate (LayoutInflater.java:353)
android.support.v7.app.AppCompatDelegateImplV7.setContentView (AppCompatDelegateImplV7.java:280)
android.support.v7.app.AppCompatActivity.setContentView (AppCompatActivity.java:140)
com.chalkstreet.app.home.HomeActivity.onCreate (HomeActivity.java:334)
android.app.Activity.performCreate (Activity.java:5264)
android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1088)
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2302)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2390)
android.app.ActivityThread.access$800 (ActivityThread.java:151)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1321)
android.os.Handler.dispatchMessage (Handler.java:110)
android.os.Looper.loop (Looper.java:193)
android.app.ActivityThread.main (ActivityThread.java:5292)
java.lang.reflect.Method.invokeNative (Method.java)
java.lang.reflect.Method.invoke (Method.java:515)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:824)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:640)
dalvik.system.NativeStart.main (NativeStart.java)
arrow_drop_down
Caused by java.lang.reflect.InvocationTargetException:
java.lang.reflect.Constructor.constructNative (Constructor.java)
java.lang.reflect.Constructor.newInstance (Constructor.java:423)
android.view.LayoutInflater.createView (LayoutInflater.java:594)
android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:696)
android.view.LayoutInflater.rInflate (LayoutInflater.java:755)
android.view.LayoutInflater.rInflate (LayoutInflater.java:758)
android.view.LayoutInflater.rInflate (LayoutInflater.java:758)
android.view.LayoutInflater.parseInclude (LayoutInflater.java:839)
android.view.LayoutInflater.rInflate (LayoutInflater.java:745)
android.view.LayoutInflater.inflate (LayoutInflater.java:492)
android.view.LayoutInflater.inflate (LayoutInflater.java:397)
android.view.LayoutInflater.inflate (LayoutInflater.java:353)
android.support.v7.app.AppCompatDelegateImplV7.setContentView (AppCompatDelegateImplV7.java:280)
android.support.v7.app.AppCompatActivity.setContentView (AppCompatActivity.java:140)
com.chalkstreet.app.home.HomeActivity.onCreate (HomeActivity.java:334)
android.app.Activity.performCreate (Activity.java:5264)
android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1088)
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2302)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2390)
android.app.ActivityThread.access$800 (ActivityThread.java:151)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1321)
android.os.Handler.dispatchMessage (Handler.java:110)
android.os.Looper.loop (Looper.java:193)
android.app.ActivityThread.main (ActivityThread.java:5292)
java.lang.reflect.Method.invokeNative (Method.java)
java.lang.reflect.Method.invoke (Method.java:515)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:824)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:640)
dalvik.system.NativeStart.main (NativeStart.java)
arrow_drop_down
Caused by java.lang.NoClassDefFoundError: net.steamcrafted.materialiconlib.R$styleable
net.steamcrafted.materialiconlib.MaterialIconView.init (MaterialIconView.java:79)
net.steamcrafted.materialiconlib.MaterialIconView. (MaterialIconView.java:34)
java.lang.reflect.Constructor.constructNative (Constructor.java)
java.lang.reflect.Constructor.newInstance (Constructor.java:423)
android.view.LayoutInflater.createView (LayoutInflater.java:594)
android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:696)
android.view.LayoutInflater.rInflate (LayoutInflater.java:755)
android.view.LayoutInflater.rInflate (LayoutInflater.java:758)
android.view.LayoutInflater.rInflate (LayoutInflater.java:758)
android.view.LayoutInflater.parseInclude (LayoutInflater.java:839)
android.view.LayoutInflater.rInflate (LayoutInflater.java:745)
android.view.LayoutInflater.inflate (LayoutInflater.java:492)
android.view.LayoutInflater.inflate (LayoutInflater.java:397)
android.view.LayoutInflater.inflate (LayoutInflater.java:353)
android.support.v7.app.AppCompatDelegateImplV7.setContentView (AppCompatDelegateImplV7.java:280)
android.support.v7.app.AppCompatActivity.setContentView (AppCompatActivity.java:140)
com.chalkstreet.app.home.HomeActivity.onCreate (HomeActivity.java:334)
android.app.Activity.performCreate (Activity.java:5264)
android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1088)
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2302)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2390)
android.app.ActivityThread.access$800 (ActivityThread.java:151)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1321)
android.os.Handler.dispatchMessage (Handler.java:110)
android.os.Looper.loop (Looper.java:193)
android.app.ActivityThread.main (ActivityThread.java:5292)
java.lang.reflect.Method.invokeNative (Method.java)
java.lang.reflect.Method.invoke (Method.java:515)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:824)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:640)
dalvik.system.NativeStart.main (NativeStart.java)

Weird problem when creating a drawable with kotlin

When I was trying to create a drawable icon in a kotlin project:
image

val test1 = MaterialDrawableBuilder.with(applicationContext)
        .setIcon(MaterialDrawableBuilder.IconValue.WEATHER_RAINY)
        .setColor(Color.WHITE)

val test2 = test1.build()

Then Android Studio show a error:
Type net.steamcrafted.materialiconlib.MaterialDrawableBuilder.MaterialDrawable! is inaccessible in this context due to: net.steamcrafted.materialiconlib.MaterialDrawableBuilder.MaterialDrawable!

I was only import net.steamcrafted.materialiconlib.MaterialDrawableBuilder

Is this a bug or my mistake?
Hope someone can solve this problem, very thanks!

AutoComplete not working

I have added the .ttf file inside the Assets folder, added the gradle dependency. Unfortunately, I am unable to choose the required material icon.

In this (app:materialIcon="icon_name") xml code, I am unable to choose the required icon by the corresponding name. I have verified with various names. However, I am able to choose an icon by entering some integer value (app:materialIcon="1211"). Have I missed something somewhere? I retried the .ttf and gradle procedure but in vain. What seem to be the issue?

Regards

Support font awesome?

This project is really great, do you have any plan to support font awesome as well? It will be great if everything is in a project.

Any plan to update with new icons.

Can you please give a small tutorial how we can update library with lastest ttf file from materialdesignicons.com?

Thanks in advance.

P.S: I like to contribute if you help me on how to get list of icons from ttf.

Unit Tests for improved test coverage

Hi Team

My name is Farid. I'm a developer with great interest in making open source contributions to popular projects.

My company - DevFactory - is sponsoring me to improve unit test coverage in open source projects.

I have analysed material-icon-lib and observed that there is room for improvement of coverage. The results indicate that the project has:

Coverage: 0%, Total Lines: 733

If you are interested in having us work towards improving the project’s coverage to 80%, please let me know and we will add it to our pipeline. Our first step will be to create a pull request with a sample. Once you approve it, we'll follow up with one or two more pull requests. Our target is to increase code coverage to above 80 percent.

For an example of our work, please see these Pull Requests accepted by the community:

I'm looking forward to your confirmation.

Thank you,
Mohd Farid
Open Source Code Coverage Team
DevFactory

Cannot instantiate class

Hello,

Since this morning, I am not able to instantiate the class in a layout. AndroidStudio gave me this exception :

java.lang.RuntimeException: Font asset not found materialdesignicons-webfont.ttf at android.graphics.Typeface.createFromAsset(Typeface.java:206) at net.steamcrafted.materialiconlib.MaterialIconUtils.getTypeFace(MaterialIconUtils.java:21) at net.steamcrafted.materialiconlib.MaterialDrawableBuilder.<init>(MaterialDrawableBuilder.java:55) at net.steamcrafted.materialiconlib.MaterialDrawableBuilder.with(MaterialDrawableBuilder.java:67) at net.steamcrafted.materialiconlib.MaterialIconView.init(MaterialIconView.java:71) at net.steamcrafted.materialiconlib.MaterialIconView.init(MaterialIconView.java:75) at net.steamcrafted.materialiconlib.MaterialIconView.<init>(MaterialIconView.java:32) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:475) at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:262) at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:220) at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:186) at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:334) at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:345) at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:245) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727) at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:858) at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70) at android.view.LayoutInflater.rInflate(LayoutInflater.java:834) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:861) at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70) at android.view.LayoutInflater.rInflate(LayoutInflater.java:834) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:861) at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70) at android.view.LayoutInflater.rInflate(LayoutInflater.java:834) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:861) at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70) at android.view.LayoutInflater.rInflate(LayoutInflater.java:834) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) at android.view.LayoutInflater.inflate(LayoutInflater.java:518) at android.view.LayoutInflater.inflate(LayoutInflater.java:397) at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:324) at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:429) at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:368) at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:567) at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:549) at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:863) at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:549) at com.android.tools.idea.rendering.RenderTask.lambda$inflate$1(RenderTask.java:680) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)

Thank you for your answer

程序停止运行。

报错:android.view.ViewGroup$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams

NPE when using in NavigationView

MaterialDrawableBuilder drawable = MaterialDrawableBuilder.with(this).setColor(Color.WHITE).setIcon(MaterialDrawableBuilder.IconValue.LIBRARY_MUSIC).build();
 navigationView.getMenu().findItem(R.id.nav_library).setIcon(drawable);

Doing this results in NullPointerException in NavgationMenuItemView

java.lang.NullPointerException: Attempt to invoke virtual method 'android.graphics.drawable.Drawable android.graphics.drawable.Drawable$ConstantState.newDrawable()' on a null object reference
            at android.support.design.internal.NavigationMenuItemView.setIcon(NavigationMenuItemView.java:114)
            at android.support.design.internal.NavigationMenuItemView.setIconTintList(NavigationMenuItemView.java:144)
            at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.getView(NavigationMenuPresenter.java:325)

This only happens with design support lib 22.2.0.+. Worked fine till 22.2.0. Also broken on v23.

License

Just a small correction. Both Material Design Icons and the Google stock icons need to be referenced in the license contained in the project.

Awesome project by the way! If I get a bit I'll get it referenced on the getting started page.

Attribute "materialIcon" already defined with incompatible format.

Error:(2722) Attribute "materialIcon" already defined with incompatible format.
Error:(901) Original attribute defined here.
Error:(2722) Attribute "materialIcon" already defined with incompatible format.
Error:(901) Original attribute defined here.

ps:i crash with system attr , make the name diff can help

using icons within buttons

Hi,
How can i use icons within buttons of my my context menu layout. my context menu layout is like:

  <merge xmlns:android="http://schemas.android.com/apk/res/android">
      <Button
          android:id="@+id/btnShare"
          style="@style/ContextMenuButton"
          android:drawableRight="@android:drawable/ic_menu_share"
          android:text="@string/share.menu.share"
          android:textColor="@color/btn_context_menu_text_red" />
      <Button
          ............

API 24 Layout Editor Rendering Issues

The Layout Editor shows an issue on API 24.
API 23 shows no issues.

java.lang.NullPointerException
at android.graphics.Typeface.createAssetUid(Typeface.java:219)
at android.graphics.Typeface.createFromAsset(Typeface.java:193)
at net.steamcrafted.materialiconlib.MaterialIconUtils.getTypeFace(MaterialIconUtils.java:24)
at net.steamcrafted.materialiconlib.MaterialDrawableBuilder.(MaterialDrawableBuilder.java:55)
at net.steamcrafted.materialiconlib.MaterialDrawableBuilder.with(MaterialDrawableBuilder.java:67)
at net.steamcrafted.materialiconlib.MaterialIconView.init(MaterialIconView.java:73)
at net.steamcrafted.materialiconlib.MaterialIconView.init(MaterialIconView.java:77)
at net.steamcrafted.materialiconlib.MaterialIconView.(MaterialIconView.java:34)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:465)
at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:172)
at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:105)
at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:176)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:247)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:171)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:858)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:834)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:861)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:834)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:861)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:834)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:317)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:429)
at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:350)
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:520)
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:508)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:967)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:508)
at com.android.tools.idea.rendering.RenderTask.access$600(RenderTask.java:75)
at com.android.tools.idea.rendering.RenderTask$3.call(RenderTask.java:620)
at com.android.tools.idea.rendering.RenderTask$3.call(RenderTask.java:617)
at com.android.tools.idea.rendering.RenderService.runRenderAction(RenderService.java:371)
at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:617)
at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:639)
at com.intellij.android.designer.designSurface.AndroidDesignerEditorPanel$7.run(AndroidDesignerEditorPanel.java:519)
at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:337)
at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:327)
at com.intellij.util.ui.update.MergingUpdateQueue$3.run(MergingUpdateQueue.java:271)
at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:286)
at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:244)
at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:234)
at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)
at com.intellij.util.Alarm$Request$1.run(Alarm.java:352)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

Missing Icons

The following icons are missing:

  • periodic-table-co2
  • periscope

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.