1.首先要把我们的字体放到相应的目录下
如果我们仅仅是想要验证一个字体,我们可以直接
我们的字体push到 手机 /system/fonts/ 目录下面
2.在代码中进行设置
import android.graphics.Paint; import android.graphics.Typeface; import java.io.File; private static final String SYSTEM = "/system/fonts/"; private static final String SYSTEM_FONT_TIME_BACKGROUND = SYSTEM + "FunuiNumber-Regular.ttf"; private static Typeface sClockTypeface; private static Typeface sStandardTypeface; mDisResult = (TextView) findViewById(R.id.dis_result); File fileTTF = new File(SYSTEM_FONT_TIME_BACKGROUND); sStandardTypeface = Typeface.DEFAULT; if (sClockTypeface == null && fileTTF.exists()) { sClockTypeface = Typeface .createFromFile(SYSTEM_FONT_TIME_BACKGROUND); } Paint paint = mDisResult.getPaint(); paint.setTypeface(fileTTF.exists() ? sClockTypeface : sStandardTypeface);
但是,如果我想要把我的字体入库,就需要进行如下的操作了
1.把字体放到frameworks/base/data/fonts目录中
zhangshuli@zhangshuli-MS-7817:~/PROJECT/PROJECT_V5/32_p2_HD$ cp /home/zhangshuli/Desktop/funui_calculator.ttf frameworks/base/data/fonts/
2.在 frameworks/base/data/fonts/Android.mk注册
$(eval include $(CLEAR_VARS)) $(eval LOCAL_MODULE := $(1)) $(eval LOCAL_SRC_FILES := $(1)) $(eval LOCAL_MODULE_CLASS := ETC) $(eval LOCAL_MODULE_TAGS := optional) $(eval LOCAL_MODULE_PATH := $(TARGET_OUT)/fonts) $(eval include $(BUILD_PREBUILT)) endef font_src_files := Roboto-Regular.ttf Roboto-Bold.ttf Roboto-Italic.ttf Roboto-BoldItalic.ttf DroidSerif-Regular.ttf DroidSerif-Bold.ttf DroidSerif-Italic.ttf DroidSerif-BoldItalic.ttf DroidSansMono.ttf Clockopia.ttf AndroidClock.ttf AndroidClock_Highlight.ttf AndroidClock_Solid.ttf ifeq ($(VANZO_OOS_NUMBER_FONT_SUPPORT),yes) font_src_files += FunuiNumber-Regular.ttf #添加位置 funui_calculator.ttf endif ifeq ($(MINIMAL_FONT_FOOTPRINT),true)