自定义虚线和更换字体

1、全局字体的更换:

      首选需要定义一个类获取资源文件中的字体,定义更换字体的方法:

package com.ld.ldm.model;

import java.lang.reflect.Field;
import android.content.Context;
import android.graphics.Typeface;

public final class FontsOverride {

	public static void setDefaultFont(Context context,String staticTypefaceFieldName, String fontAssetName) 
	{
        final Typeface regular = Typeface.createFromAsset(context.getAssets(),
                fontAssetName);
        replaceFont(staticTypefaceFieldName, regular);
    }

    protected static void replaceFont(String staticTypefaceFieldName,final Typeface newTypeface)
    {
        try {
            final Field staticField = Typeface.class
                    .getDeclaredField(staticTypefaceFieldName);
            staticField.setAccessible(true);
            staticField.set(null, newTypeface);
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}
 其他方法请参考:http://www.android100.org/html/201502/14/118656.html     

应用:在BaseActivity或者Application的onCreate方法中调用:

        FontsOverride.setDefaultFont(this, "DEFAULT", "fonts/HYXiZYJF.ttf");
        FontsOverride.setDefaultFont(this, "MONOSPACE", "fonts/HYXiZYJF.ttf");
        FontsOverride.setDefaultFont(this, "SERIF", "fonts/HYXiZYJF.ttf");
        FontsOverride.setDefaultFont(this, "SANS_SERIF", "fonts/HYXiZYJF.ttf");
2.自定义虚线:

http://www.2cto.com/kf/201404/290495.html

http://blog.csdn.net/pi9nc/article/details/20995633

结合两篇博客的知识点就可以得到理想的虚线。


你可能感兴趣的:(android)