Browse Source

字体库

liukai 2 years ago
parent
commit
91b1681a86

+ 3 - 2
cpt_ewallet/src/main/res/layout/fragment_ewallet_main.xml

@@ -265,7 +265,7 @@
                             android:layout_height="@dimen/d_26dp"
                             android:src="@drawable/wallet_password_icon" />
 
-                        <TextView
+                        <com.guadou.lib_baselib.font_text_view.TextViewLight
                             android:layout_width="wrap_content"
                             android:layout_height="wrap_content"
                             android:layout_marginLeft="@dimen/d_8dp"
@@ -307,7 +307,7 @@
                             android:layout_height="@dimen/d_25dp"
                             android:src="@drawable/wallet_history_icon" />
 
-                        <TextView
+                        <com.guadou.lib_baselib.font_text_view.TextViewMedium
                             android:layout_width="wrap_content"
                             android:layout_height="wrap_content"
                             android:layout_marginLeft="@dimen/d_8dp"
@@ -353,6 +353,7 @@
                             android:layout_height="wrap_content"
                             android:layout_marginLeft="@dimen/d_8dp"
                             android:text="我的工作发票"
+                            binding:typefaceBold="@{true}"
                             android:textColor="@color/gray_76"
                             android:textSize="@dimen/d_15sp" />
 

+ 2 - 2
cs_baselib/src/main/java/com/guadou/lib_baselib/font_text_view/TextViewBold.java

@@ -1,6 +1,7 @@
 package com.guadou.lib_baselib.font_text_view;
 
 import android.content.Context;
+import android.graphics.Typeface;
 import android.util.AttributeSet;
 
 import androidx.annotation.Nullable;
@@ -27,7 +28,6 @@ public class TextViewBold extends AppCompatTextView {
     }
 
     private void applyCustomFont(Context context) {
-//        Typeface customFont = FontCache.getTypeface("PingFang_Bold.ttf", context);
-//        setTypeface(customFont);
+        setTypeface(Typeface.create("sans-serif", Typeface.BOLD));
     }
 }

+ 34 - 0
cs_baselib/src/main/java/com/guadou/lib_baselib/font_text_view/TextViewLight.java

@@ -0,0 +1,34 @@
+package com.guadou.lib_baselib.font_text_view;
+
+import android.content.Context;
+import android.graphics.Typeface;
+import android.util.AttributeSet;
+
+import androidx.annotation.Nullable;
+import androidx.appcompat.widget.AppCompatTextView;
+
+/**
+ * Custom TextView for Light
+ */
+
+public class TextViewLight extends AppCompatTextView {
+
+    public TextViewLight(Context context) {
+        super(context);
+        applyCustomFont(context);
+    }
+
+    public TextViewLight(Context context, @Nullable AttributeSet attrs) {
+        super(context, attrs);
+        applyCustomFont(context);
+    }
+
+    public TextViewLight(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
+        super(context, attrs, defStyleAttr);
+        applyCustomFont(context);
+    }
+
+    private void applyCustomFont(Context context) {
+        setTypeface(Typeface.create("sans-serif-light", Typeface.NORMAL));
+    }
+}

+ 2 - 2
cs_baselib/src/main/java/com/guadou/lib_baselib/font_text_view/TextViewMedium.java

@@ -1,6 +1,7 @@
 package com.guadou.lib_baselib.font_text_view;
 
 import android.content.Context;
+import android.graphics.Typeface;
 import android.util.AttributeSet;
 
 import androidx.annotation.Nullable;
@@ -28,7 +29,6 @@ public class TextViewMedium extends AppCompatTextView {
     }
 
     private void applyCustomFont(Context context) {
-//        Typeface customFont = FontCache.getTypeface("PingFang_Medium.ttf", context);
-//        setTypeface(customFont);
+        setTypeface(Typeface.create("sans-serif-medium", Typeface.NORMAL));
     }
 }

+ 34 - 0
cs_baselib/src/main/java/com/guadou/lib_baselib/font_text_view/TextViewRegular.java

@@ -0,0 +1,34 @@
+package com.guadou.lib_baselib.font_text_view;
+
+import android.content.Context;
+import android.graphics.Typeface;
+import android.util.AttributeSet;
+
+import androidx.annotation.Nullable;
+import androidx.appcompat.widget.AppCompatTextView;
+
+/**
+ * Custom TextView for Light
+ */
+
+public class TextViewRegular extends AppCompatTextView {
+
+    public TextViewRegular(Context context) {
+        super(context);
+        applyCustomFont(context);
+    }
+
+    public TextViewRegular(Context context, @Nullable AttributeSet attrs) {
+        super(context, attrs);
+        applyCustomFont(context);
+    }
+
+    public TextViewRegular(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
+        super(context, attrs, defStyleAttr);
+        applyCustomFont(context);
+    }
+
+    private void applyCustomFont(Context context) {
+        setTypeface(Typeface.create("sans-serif", Typeface.NORMAL));
+    }
+}

+ 18 - 7
cs_cptServices/src/main/java/com/guadou/cs_cptservices/binding/BindingTextView.kt

@@ -1,6 +1,7 @@
 package com.guadou.cs_cptservices.binding
 
 import android.graphics.Paint
+import android.graphics.Typeface
 import android.graphics.drawable.Drawable
 import android.os.Build
 import android.text.Html
@@ -65,23 +66,33 @@ fun isCenterLine(textView: TextView, isUnderline: Boolean) {
 /**
  * 设置字体
  */
+@BindingAdapter("typefaceLight")
+fun typefaceLight(textView: TextView, boolean: Boolean) {
+    textView.typeface = Typeface.create("sans-serif-light", Typeface.NORMAL)
+}
+
+@BindingAdapter("typefaceRegular")
+fun typefaceRegular(textView: TextView, boolean: Boolean) {
+    textView.typeface = Typeface.create("sans-serif", Typeface.NORMAL)
+}
+
 @BindingAdapter("typefaceMedium")
 fun typefaceMedium(textView: TextView, boolean: Boolean) {
-//    textView.typeface = TypefaceUtil.getSFMedium(textView.context)
+    textView.typeface = Typeface.create("sans-serif-medium", Typeface.NORMAL)
 }
 
 @BindingAdapter("typefaceBold")
 fun typefaceSFBold(textView: TextView, boolean: Boolean) {
-//    textView.typeface = TypefaceUtil.getSFBold(textView.context)
+    textView.typeface = Typeface.create("sans-serif", Typeface.BOLD)
 }
 
 @BindingAdapter("typefaceMediumOrBold")
 fun typefaceMediumOrBold(textView: TextView, boolean: Boolean) {
-//    if (boolean) {  //true为粗体
-//        textView.typeface = TypefaceUtil.getSFBold(textView.context)
-//    } else {
-//        textView.typeface = TypefaceUtil.getSFMedium(textView.context)
-//    }
+    if (boolean) {  //true为粗体
+        textView.typeface = Typeface.create("sans-serif", Typeface.BOLD)
+    } else {
+        textView.typeface = Typeface.create("sans-serif-medium", Typeface.NORMAL)
+    }
 }
 
 /**