Android, how to display font awesome icons in layout edit mode?

牧云@^-^@ 提交于 2020-01-06 12:56:48

问题


I'm trying to add font awesome icons into my Android App, i found a solution here:

https://stackoverflow.com/a/15762875/535556

But it display icons only after compilation of app and run on device.

After that i found this plugin:

https://github.com/bperin/FontAwesomeAndroid

But it does not work for me..

I would like to display font awesome icons directly in layout because is it much faster that compile application to check that is displayed correctly.

Many thanks for any advice.


回答1:


Make sure your ttf is in /src/main/assets/font/fontawesome.ttf (or whatever it's named, make sure it's all lower case though) Also verify that in your .iml file the assets directory matches this:


<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />.


once that is all in place then go to view where you will be displaying the icon (not the xml file, but the .java file) and in the onCreate() method or whichever you think is best, create a typeface using the fontawesome.ttf and assign it to your icon TextView, Button, or whatever visual element you want, like this:


public static final String FONT_AWESOME_PATH = "fonts/fontawesome.ttf";
private TextView leftEyeEditIcon;

leftEyeEditIcon = (TextView) findViewById(R.id.edit_icon);
leftEyeEditIcon.setTypeface(Typeface.createFromAsset(getResources().getAssets(), FONT_AWESOME_PATH));

You can then adjust the size of the icon by going into the xml.file and setting the TextSize, since this is technically a "font".



来源:https://stackoverflow.com/questions/23150677/android-how-to-display-font-awesome-icons-in-layout-edit-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!