包含1000多個material矢量圖標的安卓圖標庫:material-icon-lib
包含1000多個material矢量圖標的安卓圖標庫。 特性:Android Studio 設計模式中可以實時預覽與代碼提示。 目前包括1170個圖標,你可以在這里查看這些圖標: https://materialdesignicons.com。 配置分分鐘就可以完成。 大小為200kb(平均每個圖標170比特)。
運行效果:

使用說明:
Gradle
dependencies { compile 'net.steamcrafted:materialiconlib:1.0.3' }
步驟2
現在你可以使用MaterialIconView或者ImageView,使用MaterialDrawable作為Drawable資源。先來看看提供的view。
在xml中添加view:
<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" />
你也可以使用"wrap_content":
<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" />
這個view繼承自ImageView。這意味著你可以使用ImageView的所有特性,但是注意這個view并不會緩存它創建的任意drawable,因此每次對icon有所修改的時候,都會重新生成drawable。在listview中使用這個view是相當讓人沮喪的,如果你想在listview中使用這些icon的話,緩存drawable并結合使用MaterialDrawableBuilder和ImageView!
就如之前提到的這個類繼承自ImageView類,但有一些特有的方法:
// 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... That was easy, right? Next up the custom drawables, they are internally used by theMaterialIconView 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 theMaterialDrawableBuilder 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);
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!