-5

im using this sample code for signal info http://code.google.com/p/krvarma-android-samples/source/browse/trunk/PhoneStateSample/src/com/varma/samples/phonestatesample/PhoneStateSample.java which show signal strength in progressbar below is my code which piece of cdoe i took from that sample class my question is how i will change color of progressbar which create programiclaly?

                private void setSignalLevel(int id,int infoid,int level){
            int progress = (int) ((((float)level)/31.0) * 100);
            String signalLevelString = getSignalLevelString(progress);

            ((ProgressBar)findViewById(id)).setProgress(progress);

            ((TextView)findViewById(infoid)).setText(signalLevelString);

            Log.i("signalLevel ","" + progress);
    }
  • Go to this [http://stackoverflow.com/questions/2020882/how-to-change-progress-bars-progress-color-in-android?rq=1](http://stackoverflow.com/questions/2020882/how-to-change-progress-bars-progress-color-in-android?rq=1) – M D Mar 26 '14 at 12:52
  • im not using xml for progressbar – user3456519 Mar 26 '14 at 12:54
  • @user3456519 do you know what Drawable class is for? if so try to call setProgressDrawable with your own custom Drawable – pskink Mar 26 '14 at 12:56

1 Answers1

0

try this:

yourProgressBar.getProgressDrawable().setColorFilter(Color.RED, Mode.MULTIPLY);

in your case:

((ProgressBar)findViewById(id)).getProgressDrawable().setColorFilter(Color.RED, Mode.MULTIPLY);
Vikram Singh
  • 1,420
  • 14
  • 19
  • i dont know the name of my progressbar seee this ecxample i folllow this http://code.google.com/p/krvarma-android-samples/source/browse/trunk/PhoneStateSample/src/com/varma/samples/phonestatesample/PhoneStateSample.java – user3456519 Mar 26 '14 at 13:02
  • for your case i have added the code... – Vikram Singh Mar 26 '14 at 13:13
  • ok thanx but tell me only 1 help more in example code which i used its check battery level at this line if(level > EXCELLENT_LEVEL) signalLevelString = "Excellent"; how i wil change color of progressbar at that stage??? – user3456519 Mar 26 '14 at 13:25
  • write same line of code inside this if (level > EXCELLENT_LEVEL) condition and some different color.. – Vikram Singh Mar 26 '14 at 13:57
  • ur code mode.Multiply will show double effect – user3456519 Mar 26 '14 at 14:27