I set accentColor yellow and on API > 21 everything works, however problems appeared on the API below - some controls are blue

  1. Progressbar

Correct view:

enter image description here

Invalid API < 21 view API < 21

enter image description here

It was possible to fix using the following lines:

 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { progressbar.getIndeterminateDrawable().setColorFilter(ContextCompat.getColor(this, R.color.accent), PorterDuff.Mode.SRC_ATOP); } 

How to fix this problem by overriding the ProgressBar style?

  1. The same problem with Activity settings, with switches and names PreferenceCategory - how I can’t fix it at all

enter image description here

If it helps to extract from xml , where I form elements

 <PreferenceCategory android:title="@string/pref_category_start"> ... <SwitchPreference android:defaultValue="@string/pref_welcome_default_switch" android:key="@string/pref_welcome_key_switch" android:summary="@string/pref_welcome_summary" android:title="@string/pref_title_welcome_string" /> ... </PreferenceCategory> 

Partitioning progress bar

  <ProgressBar android:id="@+id/progressbar" style="@style/Widget.AppCompat.ProgressBar.Horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/appbar" android:indeterminate="true" /> 

I would be grateful for any help. Thanks in advance.

  • one
    What city is this weather in?) - Chaynik
  • The question was simply asked back in February :) - Roman Novoselov
  • one
    Oh damn, but then I was scared: D - Chaynik
  • whether styles or colors need to create a folder in the project. You create styles-v21 or colors-v21, in the project, the file will be expanded to 2 files. So, in the files with the ending -v21 you write lines for api 21 and higher, in another file you write for api below 21, and in v21 there will be lines that are not in a simple file - zayn1991
  • style = "@style / Widget.AppCompat.ProgressBar.Horizontal indicated the progressbar in xml? or reassigned in the styles, set the desired colors in it, and shove a new style in the ProgressBar? - Chaynik

2 answers 2

Try to install colorControlNormal , based on the description, this is directly what sets the color to the components. For the switch, respectively, colorSwitchThumbNormal .

From \ sdk \ extras \ android \ support \ v7 \ appcompat \ res \ values ​​\ attrs.xml

 <!-- The primary branding color for the app. By default, this is the color applied to the action bar background. --> <attr name="colorPrimary" format="color" /> <!-- Dark variant of the primary branding color. By default, this is the color applied to the status bar (via statusBarColor) and navigation bar (via navigationBarColor). --> <attr name="colorPrimaryDark" format="color" /> <!-- Bright complement to the primary branding color. By default, this is the color applied to framework controls (via colorControlActivated). --> <attr name="colorAccent" format="color" /> <!-- The color applied to framework controls in their normal state. --> <attr name="colorControlNormal" format="color" /> <!-- The color applied to framework controls in their activated (ex.checked) state. --> <attr name="colorControlActivated" format="color" /> <!-- The color applied to framework control highlights (ex. ripples, list selectors). --> <attr name="colorControlHighlight" format="color" /> <!-- The color applied to framework buttons in their normal state. --> <attr name="colorButtonNormal" format="color" /> <!-- The color applied to framework switch thumbs in their normal state. --> <attr name="colorSwitchThumbNormal" format="color" /> 
  • Added these attributes to the application root style No change: PreferenceActivity elements are blue on the API <21 <style name = "AppTheme" parent = "Theme.AppCompat.DayNight.DarkActionBar"> ... <item name = "colorControlNormal"> @ color / accent </ item> <item name = "colorSwitchThumbNormal"> @ color / accent </ item> </ style> - Roman Novoselov

If you use PreferenceActivity

  1. Replace PreferenceActivity to acc. heir AppCompatActivity from the appcompat-v7 library.
  2. Use PreferenceFragment .
  • I use them - Roman Novoselov
  • In that case, please indicate this in the question. - Stas Lelyuk