I can’t insert a Switch in my project because of the following error :
View requires API level 14 (current min is 8):
But in my project properties, I use Platform 4.1 and API Level 16. So what is wrong?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is a nice lecture about this from Google IO 2012 (starting at slide 32)
Here is a detailed example:
Create a separate layout XML file for ICS+ versions by placing it in /res/layout-v14. The resulting file structure will look something like this:
Android will then look for resources in the layout-v14 directory when your app is running on v14 or higher.
Place an include in mainlayout.xml that will pull in the pertinent compound_button.xml when the app is run:
For the pre 4.0 layout we want a checkbox, so create /layout/compound_button.xml as a merge as follows:
And then for the 4.0+ layout we want a switch, so create /layout-v14/compound_button.xml as a merge as follows:
Of course, be sure to set your min and targets appropriately: