Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the default color of ?attr/colorControlHighlight in android?

Tags:

android

colors

I need to know the default color of ?attr/colorControlHighlight in android because I need to apply the same color for my buttons press state background in my drawable for pre lollipop devices. ?attr/colorControlHighlight is one of the attributes from lollipop that you can't use on pre lollipop or else it would trigger an error.

like image 300
Earwin delos Santos Avatar asked Aug 27 '15 10:08

Earwin delos Santos


1 Answers

?attr/colorControlHighlight is a reference to a colorControlHighlight value defined in attr xml.

attrs.xml is a file located in:

android_sdk\platforms\android-22\data\res\values\attrs.xml

Here, all of the attributes, that you may use in your app, are located.

If we check that file, we will find

<attr name="colorControlHighlight" format="color" /> string,

which means that colorControlHighlight itself is a reference to a color.

And all attributes declared here are just references to another values. The actual values are assigned in themes.xml file, which, in it's turn, is located in:

android-sdk\platforms\android-22\data\res\values\themes.xml

If we check that file, we'll find, that there are a lot of themes, which are using our colorControlHighlight reference. So whether you are using one theme or another in your application, the colorControlHighlight values would be different for each of them.

In our case there are 2 themes:

<item name="colorControlHighlight">@color/legacy_button_pressed</item> for Theme

and

<item name="colorControlHighlight">@color/legacy_light_button_pressed</item> for Theme.Light

Here we see another references instead of values. But now they refer to the color attribute: @color/. Thus we need to move to the color.xml files.

These are

android-sdk\platforms\android-22\data\res\values\colors.xml

android-sdk\platforms\android-22\data\res\values\colors_holo.xml

android-sdk\platforms\android-22\data\res\values\colors_leanback.xml

android-sdk\platforms\android-22\data\res\values\colors_legacy.xml

android-sdk\platforms\android-22\data\res\values\colors_material.xml

Simple file check brings out the actual values we were looking for:

in the colors-legacy.xml file:

<color name="legacy_button_pressed">#fffea50b</color>

and

<color name="legacy_light_button_pressed">@color/legacy_button_pressed</color> which also refers to the first color.

So, the color we searched for, was #fffea50b

like image 106
endasan Avatar answered Nov 12 '22 01:11

endasan