How to add fontawesome font to Android Android 11.10.2016

android_fontawesome.png

FontAwesome offers more than 605 fonts icons in a single collection. It has infinite scalability which means every icon looks great and awesome at any size and color you define. This library allows you to include vector icons everywhere in your project.

Already available fonts

  • Google Material Design Icons
  • Material Design Iconic Font
  • Fontawesome
  • Meteocons
  • Octicons
  • Community Material
  • Weather Icons
  • Typeicons
  • Entypo
  • Devicon
  • Foundation Icons
  • Ionicons

Add the iconics-core dependency to your android module build.gradle.

compile "com.mikepenz:iconics-core:2.8.1@aar"
compile "com.android.support:appcompat-v7:${supportLibVersion}"

Add desired fonts dependency to your android module build.gradle.

compile 'com.mikepenz:google-material-typeface:2.2.0.3.original@aar' 
compile 'com.mikepenz:material-design-iconic-typeface:2.2.0.2@aar'
compile 'com.mikepenz:fontawesome-typeface:4.6.0.3@aar'
compile 'com.mikepenz:octicons-typeface:3.2.0.2@aar'
compile 'com.mikepenz:meteocons-typeface:1.1.0.2@aar'
compile 'com.mikepenz:community-material-typeface:1.5.54.2@aar'
compile 'com.mikepenz:weather-icons-typeface:2.0.10.2@aar'
compile 'com.mikepenz:typeicons-typeface:2.0.7.2@aar'
compile 'com.mikepenz:entypo-typeface:1.0.0.2@aar'
compile 'com.mikepenz:devicon-typeface:2.0.0.2@aar'
compile 'com.mikepenz:foundation-icons-typeface:3.0.0.2@aar'
compile 'com.mikepenz:ionicons-typeface:2.0.1.2@aar'

Define IconicsLayoutInflater to enable automatic xml icons detection (optional). Set the IconicsLayoutInflater as new LayoutInflaterFactory. This will enable automatic icon detection for TextViews, Buttons, and allow you to set icons on ImageView's via xml. This does not work on FAB's please use the Context-Injection instead.

@Override
protected void onCreate(Bundle savedInstanceState) {
    LayoutInflaterCompat.setFactory(getLayoutInflater(), new IconicsLayoutInflater(getDelegate()));
    //...
    super.onCreate(savedInstanceState);
    //...
}

Or inject into Context. Wrap the Activity context. This will enable the same features as in previous advice, but is not compatible with other libs wrapping the baseContext.

@Override
protected void attachBaseContext(Context newBase) {
    super.attachBaseContext(IconicsContextWrapper.wrap(newBase));
}

Use as drawable

new IconicsDrawable(this)
    .icon(FontAwesome.Icon.faw_android)
    .color(Color.RED)
    .sizeDp(24)
    //.actionBarSize()

Use as ImageView (only available if you set IconicsLayoutInflater or inject the context)

<ImageView
    android:layout_width="48dp"
    android:layout_height="48dp"
    app:ico_color="@color/red"
    app:ico_icon="faw-android"
    app:ico_size="48dp" />

    //other possible attributes
    //app:ico_background_color="@android:color/transparent"
    //app:ico_color="@color/md_red_100"
    //app:ico_contour_color="@android:color/transparent"
    //app:ico_contour_width="0dp"
    //app:ico_corner_radius="0dp"
    //app:ico_icon="gmd-plus-circle"
    //app:ico_offset_x="0dp"
    //app:ico_offset_y="0dp"
    //app:ico_padding="0dp"
    //app:ico_size="48dp"

Use as TextView (only available if you set IconicsLayoutInflater or inject the context)

<TextView
    android:text="{faw-android} Android"
    android:textColor="@android:color/black"
    android:layout_width="wrap_content"
    android:layout_height="56dp"
    android:textSize="16sp"/>

Use as custom views (if you do not set IconicsLayoutInflater or inject the context)

Use as IconicsImageView

<com.mikepenz.iconics.view.IconicsImageView
    android:layout_width="72dp"
    android:layout_height="72dp"
    app:iiv_color="@android:color/holo_red_dark"
    app:iiv_icon="faw-android" />

Use as IconicsTextView

<com.mikepenz.iconics.view.IconicsTextView
        android:text="{faw-android}"
        android:textColor="@android:color/black"
        android:layout_width="wrap_content"
        android:layout_height="56dp"
        android:textSize="16sp"/>

Use as IconicsButton

<com.mikepenz.iconics.view.IconicsButton
        android:text="{faw-android} Android"
        android:layout_width="120dp"
        android:layout_height="60dp"/>