问题
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