Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8760605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:05:26+00:00 2026-06-13T15:05:26+00:00

I have an Android app with a dynamically updating percentage (between 0 and 100).

  • 0

I have an Android app with a dynamically updating percentage (between 0 and 100). The app has two specific colors – light red (#BD4141) and light green (#719D98).

I would like an element to have the light red color background when the given percentage is 0 and light green when it’s 100. Intermediary percentage should represent a soft transition color representation between these two colors.

Alternatively, I would like it to go from solid red to solid green.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T15:05:27+00:00Added an answer on June 13, 2026 at 3:05 pm

    This code is not optimized but it does what it is meant to do.

    public class MainActivity extends Activity {
    
        @Override
        public void onCreate(final Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            setContentView(R.layout.screen_main);
    
            final SeekBar sb = (SeekBar) findViewById(R.id.seekBar);
            sb.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
    
                @Override
                public void onStopTrackingTouch(final SeekBar seekBar) {
                }
    
                @Override
                public void onStartTrackingTouch(final SeekBar seekBar) {
                }
    
                @Override
                public void onProgressChanged(final SeekBar seekBar,
                        final int progress, final boolean fromUser) {
                    update(seekBar);
                }
            });
            update(sb);
        }
    
        private void update(final SeekBar sb) {
            final RelativeLayout layout = (RelativeLayout) findViewById(R.id.layout);
    
            final int colorStart = Color.parseColor("#BD4141");
            final int colorEnd = Color.parseColor("#719D98");
    
            layout.setBackgroundColor(interpolateColor(colorStart, colorEnd,
                    sb.getProgress() / 100f)); // assuming SeekBar max is 100
        }
    
        private float interpolate(final float a, final float b,
                final float proportion) {
            return (a + ((b - a) * proportion));
        }
    
        private int interpolateColor(final int a, final int b,
                final float proportion) {
            final float[] hsva = new float[3];
            final float[] hsvb = new float[3];
            Color.colorToHSV(a, hsva);
            Color.colorToHSV(b, hsvb);
            for (int i = 0; i < 3; i++) {
                hsvb[i] = interpolate(hsva[i], hsvb[i], proportion);
            }
            return Color.HSVToColor(hsvb);
        }
    
    }
    

    This answer is based on question and answers from android color between two colors, based on percentage?.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with an existing Android app and I need to have a dynamically
I have an Android app, that is using the SIM Toolkit. The application has
I have an android app which has native code. The native code needs to
I have an Android app that has an Application class and I have another
I have a method in my Android app that takes a dynamically set font
I am facing a problem in my android app. I have to dynamically find
i have a spinner an two buttons on my Android app, the spinner is
How can I dynamically add a gallery to an android app, I have: Gallery
I have android app . i should pass the data from android to web
I have Android client app that communicates with server using Socket . On my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.