Get the drawable used as a CheckBox image

3

Whenever I have to save the image associated with a checkbox through the imagem = minha_checkbox.getButtonDrawable(); method it always gives me an error called call requires API level 23 (current min is 17)

How can I resolve this?

    
asked by anonymous 10.12.2016 / 18:09

1 answer

5

The getButtonDrawable () method was only introduced in the CheckBox class (CompoundButton ) in version 23 of the API.

You have two solutions:

  • Changes the minimum version of the application to 23 (% with%).
  • It uses the CompoundButtonCompat class and uses its static getButtonDrawable () :

    imagem = CompoundButtonCompat.getButtonDrawable(minha_checkbox);
    

    Note: You need the Android Support Library, revision 23.0.1 or higher.

10.12.2016 / 19:04