zoukankan      html  css  js  c++  java
  • Android 使用自定义字体

    整个项目要使用第三方字体首先将字体文件放到assets文件夹下

    因为整个项目要用第三方字体这里我重写了 TextView Button EditText 三个控件 

    以TextView 为例代码如下  其它控件一样换下继承

    public class CustomTextView extends TextView { 
    
        public CustomTextView(Context context) {
            super(context);
            init(context);
        }
    
        public CustomTextView(Context context, AttributeSet attrs) {
            super(context, attrs);
            init(context);
        }
    
        public CustomTextView(Context context, AttributeSet attrs, int defSyle) {
            super(context, attrs, defSyle);
            init(context);
        }
    
        /***
         * 设置字体
         * 
         * @return
         */
        public void init(Context context) { 
            setTypeface(FontCustom.setFont(context));
            
        }
    }
    View Code
    public class FontCustom {
        
        static String fongUrl = "fonts/fzltxh_gbk.ttf";
        static Typeface tf;
    
        /***
         * 设置字体
         * 
         * @return
         */
        public static Typeface setFont(Context context) {
            if(tf==null){
                tf = Typeface.createFromAsset(context.getAssets(), fongUrl);
            }
            return tf;
        }
    }
    View Code

    使用方法

    <CustomTextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"  
                    android:text="我是自定义字体"
                    android:textColor="@color/login_font_hit"
                    android:textSize="14.0sp" />
    View Code

    这样就实现了项目字体统一风格

  • 相关阅读:
    Elasticsearch集群+kibana
    kafka集群搭建
    Zookeeper集群搭建
    Hadoop+Hbase+Zookeeper分布式存储构建
    正则文本处理
    Haproxy+keepalived高可用集群实战
    httpsqs消息队安装
    LVS-TUN模式
    一.4.序列化使用之机柜资源及序列化高级用法
    一.3.序列化使用之idc资源与api文档
  • 原文地址:https://www.cnblogs.com/freexiaoyu/p/4159875.html
Copyright © 2011-2022 走看看