File tree Expand file tree Collapse file tree 3 files changed +27
-6
lines changed
Expand file tree Collapse file tree 3 files changed +27
-6
lines changed Original file line number Diff line number Diff line change @@ -581,6 +581,7 @@ allprojects {
581581-FastTextView不仅支持支持四个方向drawable的不同Padding和宽高,也支持设置中粗和圆角边框,所有支持的参数如下:
582582| 参数 | 说明 | 类型 | 默认值 |
583583| ------ | ------ | ------ | ------ |
584+ | fastTextView_textBoldFontWeight | 设置粗体大小,优先级高于fastTextView_textMediumBold | Float,例如1 | 0 |
584585| fastTextView_textMediumBold | 设置中粗 | boolean,例如true | false |
585586| fastTextView_leftImageHeight | 左边方向drawable高度 | dimension,例如10dp | 0 |
586587| fastTextView_leftImageWidth | 左边方向drawable宽度 | dimension,例如10dp | 0 |
Original file line number Diff line number Diff line change @@ -43,6 +43,11 @@ open class FastTextView @JvmOverloads constructor(
4343 field = value
4444 if (value) setTextMediumBold() else disableTextMediumBold()
4545 }
46+ var textBoldFontWeight: Float = 0f
47+ set(value) {
48+ field = value
49+ setTextBoldFontWeight(value)
50+ }
4651
4752 /* *
4853 * 初始化读取参数
@@ -112,8 +117,18 @@ open class FastTextView @JvmOverloads constructor(
112117 R .styleable.FastTextView_fastTextView_bottomImagePadding ,
113118 0
114119 )
115- isTextMediumBold =
116- typedArray.getBoolean(R .styleable.FastTextView_fastTextView_textMediumBold , false )
120+ val fontWeight =
121+ typedArray.getFloat(R .styleable.FastTextView_fastTextView_textBoldFontWeight , 0f )
122+ if (fontWeight > 0f ) {
123+ textBoldFontWeight = fontWeight
124+ } else {
125+ isTextMediumBold =
126+ typedArray.getBoolean(
127+ R .styleable.FastTextView_fastTextView_textMediumBold ,
128+ false
129+ )
130+ }
131+
117132 } finally {
118133 typedArray.recycle()
119134 }
@@ -309,14 +324,18 @@ open class FastTextView @JvmOverloads constructor(
309324/* *
310325 * 设置文本字体为中粗
311326 */
312- fun TextView.setTextMediumBold () = this .setTextMediumBold(1f )
313- fun TextView.setTextMediumBold (mediumWeight : Float ) {
327+ fun TextView.setTextMediumBold () = this .setTextBoldFontWeight(1f )
328+
329+ /* *
330+ * 设置文字粗体
331+ */
332+ fun TextView.setTextBoldFontWeight (fontWeight : Float ) {
314333 paint.style = Paint .Style .FILL_AND_STROKE
315- paint.strokeWidth = mediumWeight
334+ paint.strokeWidth = fontWeight
316335 invalidate()
317336}
318337
319338/* *
320339 * 禁用文本字体中粗
321340 */
322- fun TextView.disableTextMediumBold () = setTextMediumBold (0f )
341+ fun TextView.disableTextMediumBold () = setTextBoldFontWeight (0f )
Original file line number Diff line number Diff line change 1515 <attr name =" fastTextView_bottomImageWidth" format =" dimension" />
1616 <attr name =" fastTextView_bottomImagePadding" format =" dimension" />
1717 <attr name =" fastTextView_textMediumBold" format =" boolean" />
18+ <attr name =" fastTextView_textBoldFontWeight" format =" float" />
1819 </declare-styleable >
1920</resources >
You can’t perform that action at this time.
0 commit comments