In my app there are a lot of places where i have to programmatically add icons into my textviews.
On the Android material design website i saw, that you can use icon fonts, but there is nothing that indicates that you can do this inside an android app, lose from the png and svg icons itself.
http://google.github.io/material-design-icons/
is it possible to use icon-fonts in android? and if it is possible how do i implemented this into my app?
can someone help me with this?.
With the latest version of the Android Studio, you can now generate the Material icon by
In Android Studio, open an Android app project.
In the Project window, select the Android view.
Right-click the res folder and select New > Vector Asset.
Vector images can also be generated by selecting vector image option
More information about vector assets can be found here https://developer.android.com/studio/write/vector-asset-studio
You could have a look at the Android-Ionics library: https://github.com/mikepenz/Android-Iconics
It has many built-in fonts including the Material Design Icon Font and can be used for ImageViews, TextViews and Buttons.
Apart from that you can use the Material Design Icon Font like any other font:
Download .ttf file and save it under main/assets/fonts
Define strings for the unicode values you need, e.g. something like
<string name="myicon"></string>
Load typeface in your application and set typeface for textview
Use string myicon as text in your textview
Unfortunately I can't find built-in solution for this, but you can check this samples with external libs
http://blog.shamanland.com/2013/11/how-to-use-icon-fonts-in-android.html
http://fortawesome.github.io/Font-Awesome/icon/android/
http://code.tutsplus.com/tutorials/how-to-use-fontawesome-in-an-android-app--cms-24167
Related
I would like to use FontAwesome's icons in an android project. I was wondering if it's possible to possible to control the primary and secondary color of the SVG icons for example when in ImageView or maybe use the font version and use a TextView.
Any advise is welcome.
I downloaded some icons from material.io but they only offer the icons in black. I saw a youtube video where they use to allow you to choose the color. Anyway, I am trying to change the colors of the icons to white. I am not having any luck. I tried to change the fill color in android studio but it doesn't work. Any assistance would be appreciated such as exact code and files to add the code to. Thanks.
simply you can use
android:tint="#android:color/white"
You can directly download these images in Android Studio.
res > right click > New > Image Asset and select
Icon Type : Action Bar and Tab Icones
Asset Type : Clip Art
Theme : CUSTOM
And you can select any clip art that you want, select the color, padding, etc ...
As mentioned before, the material.io icons can be downloaded directly with Android Studio. This solution shows the importing of vector asset icons which are easier to manage since they are stored in a single location (res/drawable) vs. image assets that will have each icon stored in specific density folders (hdpi, xhdpi, etc).
expand the "res" folder
right click drawable
hover over "new"
select "Vector Asset"
click the image next to "icon"
select desired material.io icon
Name the icon what you would like
select "next"
Now you will have two options of setting the icon color
In the layout by using the android:tint attribute of an ImageView. This is my preference because the icon can be viewed prior to runtime.
or
In Java.
imageView.setColorFilter(ContextCompat.getColor(context, android.R.color.white),
PorterDuff.Mode.MULTIPLY);
https://material.io/icons/ actually does let you download icons in white.
But, depending on what exactly you want to do, there are a few options. If you simply want white icons (and not to change them at runtime), you may find this plugin for Android Studio useful: https://github.com/konifar/android-material-design-icon-generator-plugin
It allows you to generate the material design icons right in Android Studio, in whatever color you want. Another alternative for downloading these icons in different colors is https://materialdesignicons.com/.
If you do want to color the icons at runtime, try something like this:
imageView.setColorFilter(ContextCompat.getColor(context, android.R.color.white),
PorterDuff.Mode.MULTIPLY);
You can download white icons from material.io. also look at themes and theme overlays
Instead of android:src
I use attribute android:foreground
android:foreground="#drawable/ic_add"
For those not getting what they want yet try changing the PorterDuff mode, the following is what did it for me
imageView.setColorFilter(ContextCompat.getColor(context, android.R.color.white),
PorterDuff.Mode.SRC_ATOP);
maybe
app:iconTint help you, I am writing this because of the following reference.
Material Design 3
I want to use the new material icons provided by Google. I find it a bit cumbersome to download each icon individually.
Is there a way to do something like:
<ImageButton
android:src="#android:Icon.Material.IconName"
.../>
If not, whats the easiest way to include multiple icons in my project?
Cheers.
Follow these steps to start Vector Asset Studio:
In Android Studio, open an Android app project.
In the Project window, select the Android view.
Right-click the res folder and select New > Vector Asset.
After you open Vector Asset Studio, you can add a material icon as follows:
Select "Material Icon"
Click Choose
Select a material icon
Checkout if this can be helpful:
https://github.com/google/material-design-icons
I would like to add a delete icon (trashcan) in my actionbar. Is it a default icon can that an app can use or should the icon be a drawable in the app itself?
You can use #android:drawable/ic_menu_delete in your menu XML. This will show the default delete icon across different versions of Android (meaning it will be different on different OS versions). If you want it to be consistent across all versions, you can also download icons from https://github.com/google/material-design-icons and include them in your project drawables folder.
I would very much recommend this icon pack from Google:
https://github.com/google/material-design-icons/releases
It includes their set of Material design icons.
Navigable here:
https://www.google.com/design/icons/
Update:
This repository is extremely useful, with many Google / Custom icons:
https://materialdesignicons.com/
I am integrating ActionBarSherlock in my app and I want to have some menus with some items and its respective icons.
I have looked into samples and documentation, and everything seems to be clear, but when I Inflate the menu, I can see just the text because there are no icons related to each item yet.
I would like to use the icons you see when creating an android project:
But I can't find it, and I don't want to use direct reference to android.R.drawable in order to use those clipart icons, because I have read it is recommended to have the files in drawable folders.
android-sdk/platforms/android-xx/data/res/drawable-yyyy
where xx is your target platform and yyyy is mdpi, hdpi, etc.
Copy the icons you want into the appropriate resource folder in your project.
I generally use Android Asset Studio to create icons for my apps. It has all the standard clipart, and can generate the proper files for all other icons as well.
http://developer.android.com/design/downloads/index.html site has Action Bar Icon Pack
You can use system icons by using "#android:" prefix. The icon is not copied to drawable folders, so the application size is smaller"
Example: android:icon="#android:drawable/ic_menu_preferences"
List of icons at /platforms/android-/data/res/drawable-hdpi
Note 1: If you want to copy the icons to drawable files you can also do it in eclipse by using file /new/other/Anddoid icon set/clipart button/choose button.
Note 2: the icon set could change among platforms. That is why people are suggesting to copy resources. If the applicacion is just at development state you could just link the platform icons