How can I use ?android:attr/ xml elements with API 7?
For API 15 it works as expected, but the older ones throw errors.
<TextView
...
android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
android:paddingRight="?android:attr/listPreferredItemPaddingRight"
android:minHeight="?android:attr/l istPreferredItemHeightSmall" />
If you are targeting a minimum API level of 7, but depending on support from API 15 that’s not going to work in many cases.
Now having said that there are some attributes that translate fine between a lower and higher API, but many depend on corresponding API support so you have to test for that.
My approach has been to pick my lowest API, but build with the higher API and include the support package for the lower API that makes some higher level support available (fragments for instance)
To see if you are going to encounter any issues you would set the minimum API to 7 in your manifest, and add API 15 in your projects android properties.
Then build and deploy to an emulator using API 7, if it works great, if not you will need to find a different way to do what you are trying to accomplish to support both platforms.
You can also create different layouts for different API levels, you can also check at runtime to see if a class/method is supported before using it, but that can add a lot of overhead to your code.
This requires care since it’s quite easy to include and API that won’t work on the lowest level you have chosen to support yet misses getting exercised in your emulator testing.
My approach when I feel I have to do that is to compile with the lowest API level (API properties in the project) and make sure all such cases are known and handled in code, by versioning layouts, or are understood and have been exercised
Then switch back to the higher API, you have to be disciplined to do this or risk crashes in a release, honestly it’s usually not worth the effort because you can almost always find a x-api work around, but every case is different.