进度条优化

This commit is contained in:
renhaoting 2025-11-24 16:49:57 +08:00
parent a2b8a6700a
commit ea4cd36ffb
3 changed files with 27 additions and 9 deletions

View File

@ -28,6 +28,11 @@ class BenefitTaskItemView @JvmOverloads constructor(
}
}
}
with(mBinding.progressBar) {
setMax(100)
setProgress(0)
}
}
fun setActionFun(action: ()->Unit) {

View File

@ -2,18 +2,20 @@ package com.ama.core.architecture.widget
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.util.AttributeSet
import android.view.View
import androidx.core.graphics.withSave
import com.ama.core.architecture.R
import com.ama.core.architecture.util.ResUtil
class CustomProgressBar(context: Context, attrs: AttributeSet) : View(context, attrs) {
private var progress = 0
private var max = 100
private val grayColor = Color.parseColor("#1affffff")
private val greenColor = Color.parseColor("#ff00ff09")
private var mBgColor = ResUtil.getColor(R.color.gray_d3)
private var mForColor = ResUtil.getColor(R.color.green_09)
@ -26,13 +28,16 @@ class CustomProgressBar(context: Context, attrs: AttributeSet) : View(context, a
val width = measuredWidth.toFloat()
val height = measuredHeight.toFloat()
paint.color = grayColor
canvas.drawRoundRect(0f, 0f, width, height, width/2, 0F, paint)
val progressWidth = (width) * progress / max
if (progressWidth > 0) {
paint.color = greenColor
canvas.drawRoundRect(0f, 0f, progressWidth, height, width/2, 0F, paint)
canvas.withSave {
paint.color = mBgColor
canvas.drawRoundRect(0f, 0f, width, height, height/2, height/2, paint)
val completeProgressWidth = (width) * progress / max
if (completeProgressWidth > 0) {
paint.color = mForColor
canvas.drawRoundRect(0f, 0f, completeProgressWidth, height, height/2, height/2, paint)
}
}
}
@ -46,4 +51,10 @@ class CustomProgressBar(context: Context, attrs: AttributeSet) : View(context, a
this.max = max
invalidate()
}
fun setBarColor(bgColor: Int=R.color.gray_d3, forColor: Int=R.color.green_09) {
mBgColor = ResUtil.getColor(bgColor)
mForColor = ResUtil.getColor(forColor)
invalidate()
}
}

View File

@ -53,6 +53,8 @@
<color name="white">#FFFFFF</color>
<color name="gray_3">#333333</color>
<color name="gray_9">#999999</color>
<color name="gray_d3">#FFE2D9D3</color>
<color name="green_09">#ff00ff09</color>
</resources>