How does Android support library work with target SDK level?

453 views Asked by At

I understand that I can use support libraries to add elements that aren't natively available. However, does the newest SDK version (Lollipop, for example) use these support libraries as well, or does it use native elements? E.g. if I run the app on a Lollipop device, will it use native or support elements? I'm asking because, when editing source code (in Android Studio), I'm only editing one version of the file, I can't, for example, chose to create one file for ICS, and other for Lollipop, so how does the system know which elements to use?

1

There are 1 answers

5
CommonsWare On BEST ANSWER

However, does the newest SDK version (Lollipop, for example) use these support libraries as well, or does it use native elements?

The Android framework does not use the support libraries.

if I run the app on a Lollipop device, will it use native or support elements?

If I am interpreting what you mean by "native", it uses native element. The Android framework does not use the support libraries.

I can't, for example, chose to create one file for ICS, and other for Lollipop

You are certainly welcome to detect the running API level and elect to instantiate some level-specific class. You will see this used occasionally in the framework, though it is much more common in the Android support package, particularly for ...Compat classes.

so how does the system know which elements to use?

There is only one version of Android per Android device. Hence, there is only one set of framework "elements" for the framework to use.

Some aspects of the look of the widgets are driven by themes, and each Android version ships with support for whatever stock themes existed, going back to Theme from API Level 1. If the developer has chosen to use a different theme based upon running API level (e.g., use Theme.Material as a base on Android 5.0+ but use Theme.Holo as a base on Android 4.0-4.4), that is driven by resource set qualifiers (e.g., res/values-v21/styles.xml).