標籤:android style blog http ar color os 使用 sp
整個項目要使用第三方字型首先將字型檔放到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
這樣就實現了項目字型統一風格
Android 使用自訂字型