How to use icons and symbols from Font Awesome on Native Android Application
Font Awesome seems to be working fine for me in my android app. I did the following:
- Copied
fontawesome-webfont.ttf
into my assests folder - Found the character entities for icons I wanted, using this page: http://fortawesome.github.io/Font-Awesome/cheatsheet/
Created an entry in strings.xml for each icon. Eg for a heart:
<string name="icon_heart"></string>
Referenced said entry in the view of my xml layout:
<Button
android:id="@+id/like"
style="?android:attr/buttonStyleSmall"
...
android:text="@string/icon_heart" />Loaded the font in my onCreate method and set it for the appropriate Views:
Typeface font = Typeface.createFromAsset( getAssets(), "fontawesome-webfont.ttf" );
...
Button button = (Button)findViewById( R.id.like );
button.setTypeface(font);
How to use Font Awesome icon in android application?
You can follow this answer.
First Download the fontawesome.ttf from here. And put the file in asset/fontawesome.ttf.
Then Make a FontAwesome
class which actually represents the textview of FontAwesome
like this way.
public class FontAwesome extends TextView {
public FontAwesome(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
public FontAwesome(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public FontAwesome(Context context) {
super(context);
init();
}
private void init() {
//Font name should not contain "/".
Typeface tf = Typeface.createFromAsset(getContext().getAssets(),
"fontawesome.ttf");
setTypeface(tf);
}
}
now you can use the Fontawesome class as your need and also follow the cheatsheet. to get your icon's Unicode.
So, your TextView will be like this.
<PACKAGE_NAME.FontAwesome
android:id="@+id/userLogin"
android:text=" Login Now"
android:clickable="true"
android:onClick="login"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
fontawesome icons not displaying in Android app
try to remove the version paramter ?v=3.2.1
src: url('fonts/fontawesome/fontawesome-webfont.eot');
some old webkit can't recognize the url with paramaters
Android use font-awesome font as icon in menu item
Answer is late but for future visitors there is a great library for working with font awesome in android called iconify written by JoanZapata. You can find it here
After library being corectly initialized you can do something like this with your ActionBar menu item:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
<item
android:id="@+id/item_menu
showAsAction="always"
android:title="@string/title"/>
</menu>
and from java code you only need to do something like this:
menu.findItem(R.id.item_menu).setIcon(
new IconDrawable(this, FontAwesomeIcons.fa_share)
.colorRes(R.color.ab_icon)
.actionBarSize());
Hope this would help someone :) Ask, if you have any questions:)
How to Use FontAwesome Icon in Xamarin Android
I have got worked as below:
Copy FontAwesome
ttf file to Assets
folder. Then under OnCreate()
method of Activity
page the control should be referred to the font file as below:
Activity Page:
Typeface font = Typeface.CreateFromAsset(Application.Assets, "fontawesome-webfont.ttf");
TextView txtv = (TextView)FindViewById(Resource.Id.textviewtitle);
txtv.Typeface = font;
.xaml Page:
<TextView android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:editable="false"
android:text="\uf238 Unicode To get FontAwesome icon"
android:textSize="20dp"
android:textColor="#545454"
android:textStyle="bold"
android:padding="6dp"
android:id="@+id/textviewtitle"
/>
As you see above in .xaml
Page code android:text="\uf238 Unicode To get FontAwesome icon"
, I have declared \uf238
. This is unicode
for the particular icon. Every Icon would have unique unicode
. Therefore we should use always unicode
character to get any icon displayed on control or on text.
How to make Font Awesome icons responsive with all screen sizes in Android
you can use library for responsive font or imageview or button etc for sdp library or ssp library in your gradle file which reduce your problem about it. then you can use anywhere in your project.
implementation 'com.intuit.sdp:sdp-android:1.0.6'
implementation 'com.intuit.ssp:ssp-android:1.0.6'
import these library in dependencies folder
then it will automatically popup their name as like @dimen/_16sdp etc
How to use Font Awesome in react native project without using any third party library?
i am answering it for android And ios
download font awesome zip extract the files copy fontawesome-webfont.ttf file
make /assets/fonts/ directory in your project directory
paste fontawesome-webfont.ttf into /assets/fonts/
rename the file to fontawesome.ttf
add
"rnpm": {
"assets": [
"./assets/fonts/"
]
}
into your end of package.json file like this
- run
react-native link
command into terminal in your project directory
see reslut like this
rnpm-install info Linking assets to ios project
rnpm-install info Linking assets to android project
rnpm-install info Assets have been successfully linked to your project
- make sure run again
react-native run-android
command after successfully linked
go to fontawesome cheatsheet
copy only the character code of the icon you want to apply to a text view and paste it
<Text style={{ fontFamily: 'fontawesome', fontSize: 20 }}></Text>
apply style fontFamily: 'fontawesome'
similarly you can do it for other vector icon fonts like ionicons
and others without using third party library like react-native-vector-icons
Related Topics
How to Make Sticky Headers in Recyclerview? (Without External Lib)
Android: How to Convert String to Date
How to Use Apply a Custom Drawable to Radiobutton
Trigger Mediascanner on Specific Path (Folder), How To
Measuring Text Height to Be Drawn on Canvas ( Android )
How to Rename the Android Package Name
Creating a Custom Layout for Preferences
Exclude a Class from the Build in Android Studio
How to Test Android Referral Tracking
Connectivitymanager.Connectivity_Action Deprecated
How to Use Icons and Symbols from "Font Awesome" on Native Android Application
How to Create a Simple Divider in the New Navigationview
How to Change the Default Icon on the Searchview, to Be Use in the Action Bar on Android
Could Not Find Com.Android.Tools.Build:Aapt2:3.2.0
Difference Between Activity and Fragmentactivity
How to Tell If 'Mobile Network Data' Is Enabled or Disabled (Even When Connected by Wifi)