I'm stuck with this one implementation of material LinearProgressIndicator but have no idea on how I can make it functional in that way.
My naive approach is to have different color at different percentage level such as for "10%-Red, 25%-Yellow, 35%-Orange, 50% Green". So, I just wanted to know if there exist any other way for gradient color which starts from red and goes all above upto green.
Something like this picture!
CodePudding user response:
One of the solutions can be to generate a color from the progress and update it to the progress bar.
private fun updateProgress(progress: Int) {
val color = when (progress) {
in 0..10 -> Color.RED
in 11..34 -> Color.YELLOW
in 35..54 -> Color.MAGENTA
else -> Color.GREEN
}
updateProgressBar(progress, color)
}
private fun updateProgressBar(progress: Int, color: Int) {
binding.progressBar.apply {
setProgress(progress)
setIndicatorColor(color)
}
}
CodePudding user response:
please try with custom seekbar and progress. similar type of implementation there https://azzits.wordpress.com/tag/multiple-color-progressbar/