This one baffled me for a while. I had an Android layout open in the Eclipse graphical layout editor with a TextView component. Every time I changed any of the Margin or Padding properties the widgets disappeared off the layout, even if I entered the smallest non-zero value of 1. Turns out that I needed to add the string “dip” after the number. I guess the default units for margin is something that translates to a huge distance on the layout. For example, instead of 4 enter 4dip.
- Select your font – for example, Ubuntu. Make sure you use a royalty-free font (such as that one) or you pay the appropriate licensing fee (because you could get in a world of legal pain and because don’t be a dick)
- In the root folder of your Android project, make sure there’s a folder called
fontssubdirectory is entirely optional but to my taste.
- You cannot specify the font (really the typeface) in your resources, so you have to do in code as follows
Typeface font = Typeface.createFromAsset(_activity.getAssets(), "fonts/Ubuntu-Bold.ttf"); textView.setTypeface(font);And that’s it.