3

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.

Updated Question with picture Attached the exact description

Something like this picture!

GAMING INC
  • 53
  • 5

1 Answers1

2

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)
    }
}
Jeremiah Polo
  • 641
  • 5
  • 10