|
| 1 | +#Fontify |
| 2 | + |
| 3 | +Fontify is an Android library project providing drop-in replacements for all Android TextView subclasses, allowing developers to apply custom fonts via xml layouts and/or styles. |
| 4 | + |
| 5 | +##Set Up: |
| 6 | +1) Clone Fontify locally |
| 7 | +2) Import library project into Eclipse |
| 8 | +3) Add Fontify to your app as a library project |
| 9 | + |
| 10 | +##Usage: |
| 11 | +###Getting fonts in place: |
| 12 | +1) Put your custom font file in Android's assets folder (assets/fonts/helvetica.ttf) |
| 13 | +2) Put the path to your file in your strings.xml for ease of use: |
| 14 | + |
| 15 | + <string name="FONT_HELVETICA">fonts/helvetica.ttf</string> |
| 16 | + |
| 17 | +###Applying fonts: |
| 18 | +####In styles/themes: |
| 19 | +1) Declare your style in res/values/styles.xml: |
| 20 | + |
| 21 | + <style name="CustomTextViewStyle"> |
| 22 | + <item name="font">@string/FONT_HELVETICA</item> |
| 23 | + </style> |
| 24 | +2) Use the Fontify subclass of your TextView: |
| 25 | + <com.danh32.fontify.TextView |
| 26 | + android:layout_width="match_parent" |
| 27 | + android:layout_height="wrap_content" |
| 28 | + style="@style/CustomTextViewStyle" /> |
| 29 | + |
| 30 | +####In layouts: |
| 31 | +1) Add new XML NameSpace to root element of layout: |
| 32 | + |
| 33 | + xmlns:fontify="http://schemas.android.com/apk/res-auto" |
| 34 | +2) Use the Fontify subclass of your TextView: |
| 35 | + |
| 36 | + <com.danh32.fontify.TextView |
| 37 | + android:layout_width="match_parent" |
| 38 | + android:layout_height="wrap_content" |
| 39 | + fontify:font="@string/FONT_HELVETICA" /> |
| 40 | + |
| 41 | +####In Java: |
| 42 | +Use the textView.setFont(String fontPath) or textView.setFont(int resId) method: |
| 43 | + |
| 44 | + import com.danh32.fontify.TextView; |
| 45 | + |
| 46 | + public class CustomFontActivity extends Activity { |
| 47 | + @Override |
| 48 | + onCreate (Bundle savedInstanceState) { |
| 49 | + super(savedInstanceState); |
| 50 | + |
| 51 | + TextView tv = new TextView(this); |
| 52 | + tv.setFont(R.string.FONT_HELVETICA); |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | +##License |
| 57 | + Copyright 2013 Daniel Hill |
| 58 | + |
| 59 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 60 | + you may not use this file except in compliance with the License. |
| 61 | + You may obtain a copy of the License at |
| 62 | + |
| 63 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 64 | + |
| 65 | + Unless required by applicable law or agreed to in writing, software |
| 66 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 67 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 68 | + See the License for the specific language governing permissions and |
| 69 | + limitations under the License. |
0 commit comments