Search code examples
androidcheckboxcolorstint

How to get the checkbox tint color value in android?


I have set the tint color of checkbox with following code:

checkBox.setButtonTintList(ColorStateList.valueOf(getResources().getColor(R.color.main_green_color)));

Now i want to get the tint color value from the same checkbox. Any help would be appreciated.


Solution

  • Because of you have just put a single-state-color by inserting it into ColorStateList (ColorStateList.valueOf(getResources().getColor(R.color.main_green_color)) so you can get the tint color by

    checkBox.getButtonTintList().getDefaultColor()
    

    And if you use a multi-state-colored ColorStateList then you can get the corresponded color of a specific state by

    checkBox.getButtonTintList().getColorForState(stateSet,checkBox.getButtonTintList().getDefaultColor());
    

    If you find any trouble understanding how to get color if you have multi-state-colored ColorStateList then visit this for a more clear understanding.