GithubHelp home page GithubHelp logo

ravi8x / android-font-awesome Goto Github PK

View Code? Open in Web Editor NEW
101.0 4.0 46.0 375 KB

Android library to use the Font Awesome icons in android apps

Java 100.00%
font-awesome android-icon-pack font-icons android-material-ui android-library

android-font-awesome's Introduction

Android - Font Awesome Icon

Awesome Android library to use the Font Awesome Icon collection in your android apps. This library contains the latest font awesome icon collection (v5.7.2).

Download

Demo

Tutorial

Here you can find detailed explain of the library and the usage of it considering multiple scenarios. Or you can refer this example project.

How to Use

Include the fontawesome dependency in app's build.gradle and you are good to go.

dependencies {
    // font awesome library
    implementation 'info.androidhive:fontawesome:0.0.5'
}

Referring Icon:

Font Awesome provides three set of icons Regular, Solid and Brand. All the icons can be referred from Strings resource file. For example,

@string/fa_map - Regular map icon

@string/fa_heart_solid - Solid heart icon

@string/fa_facebook - Facebook brand icon.

Displaying Text Icon: FontTextView

To display an icon in xml layout, use the FontTextView widget. This class is extended from TextView, so all the TextView related properties will apply.

<info.androidhive.fontawesome.FontTextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/fa_calendar_check_solid"
            android:textColor="@color/icon_color"
            android:textSize="@dimen/icon_size"
            app:solid_icon="true" />

solid_icon: Use this attribute to display a solid icon (true / false). brand_icon: Use this attribute to display a brand icon (true / false).

Displaying drawable Icon: FontDrawable

If you want to set an icon to a widget (buttons, menus, bottom sheet, navigation drawer), use the FontDrawable class to create font awesome drawable.

Here Paper Plane icon is set to Floating Action Button

FloatingActionButton fab = findViewById(R.id.fab);

// using paper plane icon for FAB
FontDrawable drawable = new FontDrawable(this, R.string.fa_paper_plane_solid, true, false);

// white color to icon
drawable.setTextColor(ContextCompat.getColor(this, android.R.color.white));
fab.setImageDrawable(drawable);

Displaying Icons in Menus (Bottom Navigation, Navigation Drawer, Toolbar etc.,)

You can also display Font Awesome icons in UI elements those use menu file to render items. In the below example, font awesome icons are set to Navigation Drawer items.

public class MainActivity extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        intDrawerLayout();
    }

    /**
     * Changing navigation drawer icons
     * This involves looping through menu items and applying icons
     */
    private void intDrawerLayout() {
        NavigationView navigationView = findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);

        ImageView iconHeader = navigationView.getHeaderView(0).findViewById(R.id.nav_header_icon);
        FontDrawable drawable = new FontDrawable(this, R.string.fa_font_awesome, false, true);
        drawable.setTextColor(ContextCompat.getColor(this, android.R.color.white));
        drawable.setTextSize(50);
        iconHeader.setImageDrawable(drawable);

        int[] icons = {
                R.string.fa_home_solid, R.string.fa_calendar_alt_solid, R.string.fa_user_solid,
                R.string.fa_heart_solid, R.string.fa_comment_solid, R.string.fa_dollar_sign_solid, R.string.fa_gift_solid
        };
        renderMenuIcons(navigationView.getMenu(), icons, true, false);

        int[] iconsSubmenu = {R.string.fa_cog_solid, R.string.fa_sign_out_alt_solid};

        renderMenuIcons(navigationView.getMenu().getItem(7).getSubMenu(), iconsSubmenu, true, false);
    }

    /**
     * Looping through menu icons are applying font drawable
     */
    private void renderMenuIcons(Menu menu, int[] icons, boolean isSolid, boolean isBrand) {
        for (int i = 0; i < menu.size(); i++) {
            MenuItem menuItem = menu.getItem(i);
            if (!menuItem.hasSubMenu()) {
                FontDrawable drawable = new FontDrawable(this, icons[i], isSolid, isBrand);
                drawable.setTextColor(ContextCompat.getColor(this, R.color.icon_nav_drawer));
                drawable.setTextSize(22);
                menu.getItem(i).setIcon(drawable);
            }
        }
    }
}

Demo

Note:

This library includes the Free font awesome icons only, premium icons are not available.

android-font-awesome's People

Contributors

ravi8x 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

android-font-awesome's Issues

Add mirror option

For example, one can use the fa_play_solid to create another drawable in the opposite direction.

Some of the Font Awesome Unicodes are not displaying ,Why?

Please see the screenshot of the font awesome images

Some of the images of font awesome are not displaying ,

Calling an API from Backend Server and same given as static also not displaying..Please Help me to solve this.
Eg : f3fd ,f085 like these some icon are not diplaying
Screenshot_1588213854

Support of FontAwesome Pro

Please support FontAwesome Pro. I know it would be difficult cause the user have to use his own fonts but it would be possbile to work with it more freely.

Thanks for your great work until now.

in menu.xml

Hello how ca I use it in menu.xml file

I have this code

<item android:id="@+id/menu_home" android:enabled="true" android:icon="CODE HERE" android:title="@string/home" app:showAsAction="ifRoom" />

Icon Not Showing

Hi, i tried to load the the icon using FontDrawable method. The icon not visible and no error prompt. Im loading into an imageView.

FontDrawable fd_ = new FontDrawable(mContext, R.string.fa_apple, true, true);
imgTest.setImageDrawable(fd_);

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.