Set the progress bar to API 21

I am trying to change the hue of the Progress Bar without using a method setProgressTintList, as this method requires API 21.

For example, a button press should switch between these two modes:

before after

My code is:

    int[][] states = new int[][] {
            new int[] { android.R.attr.state_enabled}, // enabled
            new int[] {-android.R.attr.state_enabled}, // disabled
            new int[] {-android.R.attr.state_checked}, // unchecked
            new int[] { android.R.attr.state_pressed}  // pressed
    };



    int[] colors = new int[] {
            getResources().getColor(R.color.my_color),
            getResources().getColor(R.color.my_color),
            getResources().getColor(R.color.my_color),
            getResources().getColor(R.color.my_color)
    };

    ColorStateList myList = new ColorStateList(states, colors);

    ProgressBar simpleProgressBar = (ProgressBar) findViewById(R.id.recording_progress);

    simpleProgressBar.setProgressTintList(myList);
+4
source share

Source: https://habr.com/ru/post/1616959/


All Articles