Skip to content

Commit 066970e

Browse files
committed
+ attr tab_use_typeface_bold
1 parent 44003bc commit 066970e

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

TabLayout/src/main/java/com/angcyo/tablayout/DslTabLayoutConfig.kt

+24-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.angcyo.tablayout
33
import android.content.Context
44
import android.graphics.Color
55
import android.graphics.Paint
6+
import android.graphics.Typeface
67
import android.util.AttributeSet
78
import android.util.TypedValue
89
import android.view.View
@@ -51,6 +52,10 @@ open class DslTabLayoutConfig(val tabLayout: DslTabLayout) : DslSelectorConfig()
5152
/**是否开启Bold, 文本加粗*/
5253
var tabEnableTextBold = false
5354

55+
/**是否使用粗体字体的方式设置粗体, 否则使用[Paint.FAKE_BOLD_TEXT_FLAG]
56+
* 需要先激活[tabEnableTextBold]*/
57+
var tabUseTypefaceBold = false
58+
5459
/**是否开启图标颜色*/
5560
var tabEnableIcoColor = true
5661

@@ -237,6 +242,11 @@ open class DslTabLayoutConfig(val tabLayout: DslTabLayout) : DslSelectorConfig()
237242
tabEnableTextBold
238243
)
239244

245+
tabUseTypefaceBold = typedArray.getBoolean(
246+
R.styleable.DslTabLayout_tab_use_typeface_bold,
247+
tabUseTypefaceBold
248+
)
249+
240250
tabEnableGradientScale = typedArray.getBoolean(
241251
R.styleable.DslTabLayout_tab_enable_gradient_scale,
242252
tabEnableGradientScale
@@ -277,11 +287,21 @@ open class DslTabLayoutConfig(val tabLayout: DslTabLayout) : DslSelectorConfig()
277287
//文本加粗
278288
paint?.apply {
279289
if (tabEnableTextBold && select) {
280-
flags = flags or Paint.FAKE_BOLD_TEXT_FLAG
281-
isFakeBoldText = true
290+
//设置粗体
291+
if (tabUseTypefaceBold) {
292+
typeface = Typeface.defaultFromStyle(Typeface.BOLD)
293+
} else {
294+
flags = flags or Paint.FAKE_BOLD_TEXT_FLAG
295+
isFakeBoldText = true
296+
}
282297
} else {
283-
flags = flags and Paint.FAKE_BOLD_TEXT_FLAG.inv()
284-
isFakeBoldText = false
298+
//取消粗体
299+
if (tabUseTypefaceBold) {
300+
typeface = Typeface.defaultFromStyle(Typeface.NORMAL)
301+
} else {
302+
flags = flags and Paint.FAKE_BOLD_TEXT_FLAG.inv()
303+
isFakeBoldText = false
304+
}
285305
}
286306
}
287307

TabLayout/src/main/res/values/attr_dsl_tab_layout.xml

+2
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@
131131
<attr name="tab_enable_ico_color" format="boolean" />
132132
<!--是否激活文本变粗-->
133133
<attr name="tab_enable_text_bold" format="boolean" />
134+
<!--是否使用字体的方式设置变粗效果, 需要先开启[tab_enable_text_bold]-->
135+
<attr name="tab_use_typeface_bold" format="boolean" />
134136
<!--是否激活文本颜色渐变-->
135137
<attr name="tab_enable_gradient_color" format="boolean" />
136138
<!--是否激活指示器的颜色渐变效果-->

0 commit comments

Comments
 (0)