-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
FizzerBaseLib/src/main/java/com/fizzer/base/lib/ext/TextViewExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.fizzer.base.lib.ext | ||
|
||
import android.graphics.LinearGradient | ||
import android.graphics.Shader | ||
import android.widget.TextView | ||
|
||
/** | ||
* @Author fizzer | ||
* @Data 2021/6/25 - 12:11 上午 | ||
* @Email Fizzer53@sina.com | ||
* @Describe: | ||
*/ | ||
fun TextView.setGradient(startColor: Int, endColor: Int) { | ||
var endx = paint.textSize * text.length | ||
var linearGradient = LinearGradient( | ||
0f, 0f, endx, 0f, | ||
startColor, endColor, Shader.TileMode.CLAMP | ||
) | ||
paint.shader = linearGradient | ||
invalidate() | ||
} | ||
|
||
fun TextView.setVerticalGradient(startColor: Int, endColor: Int) { | ||
var endy = lineHeight.toFloat() | ||
var linearGradient = LinearGradient( | ||
0f, 0f, 0f, endy, | ||
startColor, endColor, Shader.TileMode.CLAMP | ||
) | ||
paint.shader = linearGradient | ||
invalidate() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters