How to use Font Awesome Icons in Android

Textual style Awesome is well known symbol toolbox utilized crosswise over numerous sites. It has both free and professional accumulation of symbols, however you can discover most the symbols in free gathering itself. Every symbol will spoke to by unicode (). We utilize this unicode to show the symbol in TextView. As it’s an ordinary TextView, all the content styling characteristics (shading, measure, paddings and so forth.,) can be connected.

For a precedent on the off chance that you need to show android Robot logo, you can utilize  unicode as TextView esteem.

1. Text style Awesome Android Library

So as to utilize the textual style magnificent symbol accumulation, you need to include the textual style great textual style documents to your advantages straightforwardly and apply the fitting fontFace on to TextView which is more straightforward undertaking. Be that as it may, we need the symbols to be shown in different gadgets additionally like in Buttons, Menus, Bottom Navigation and Navigation Drawer and so on,. Showing symbol in non-literary perspectives requires some exertion. So I have composed a library by fusing all the vital strategies to render the symbols in various gadgets.

To begin, incorporate the fontawesome in your build.gradle and match up your task.

conditions {

/textual style amazing

execution ‘info.androidhive:fontawesome:0.0.5’

}

2. How to utilize it?

2.1 Displaying Icon in TextView

The simplest method to show the textual style symbol is, utilize the FontTextView message by setting the fitting symbol name as content esteem. This gadget stretches out from AppCompatTextView, so all the content view credits applies to this gadget.

<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: To show strong symbol, set this incentive as obvious.

brand_icon: To show brand symbol, set this incentive as evident.

text style marvelous android-symbols

2.2 Using FontDrawable

Utilizing the symbol in xml design is simple, however on the off chance that you need to utilize the symbol for other gadget like catch or menu, you can utilize the FontDrawable component to apply the symbol.

For a precedent, on the off chance that you need to utilize the text style amazing symbol to Floating Action Button, you can utilize the FontDrawable as appeared as follows.

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

/utilizing paper plane symbol for FAB

FontDrawable drawable = new FontDrawable(this, R.string.fa_paper_plane_solid, genuine, false);

/white shading to symbol

drawable.setTextColor(ContextCompat.getColor(this, android.R.color.white));

fab.setImageDrawable(drawable);

text style amazing drifting activity catch

2.3 Using in Menus (Bottom Navigation, Navigation Drawer and so forth.,)

You can likewise utilize the text style symbols in the gadgets that utilizes menu document to render the things like Toolbar symbols, Bottom Navigation, Navigation Drawer and so on., To render the symbol in menus, you can utilize the FontDrawable to set the symbols, yet it needs few hacks through java code.

The beneath model shows tearing the text style amazing symbols in Navigation Drawer menu. Full model can be found here.

open class MainActivity broadens AppCompatActivity

executes NavigationView.OnNavigationItemSelectedListener {

@Override

ensured void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

intDrawerLayout();

}

/**

* Changing route cabinet symbols

* This includes circling through menu things and applying symbols

*/

private void intDrawerLayout() {

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, genuine);

drawable.setTextColor(ContextCompat.getColor(this, android.R.color.white));

drawable.setTextSize(50);

iconHeader.setImageDrawable(drawable);

int[] symbols = {

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(), symbols, genuine, false);

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

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

}

/**

* Looping through menu symbols are applying text style drawable

*/

private void renderMenuIcons(Menu menu, int[] symbols, boolean isSolid, boolean isBrand) {

for (int I = 0; I < menu.size(); i++) {

menuItem = menu.getItem(i);

on the off chance that (!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);

}

}

}

}

android-text style wonderful route cabinet

Leave a Reply

Your email address will not be published. Required fields are marked *