Can we use a feature that is introduced in higher version in lower versions. For example I have to use Toggle Switches in my application which has the android:minSdkVersion="4"
. But switch is introduced only from Android 4.0 (API level 14). Is there any way to implement switch option in my app.
Definitely not a silly question, Google goes into quite a lot of detail about supporting different features across Android versions. You can read up on the documentation here.
Adding support libraries to your application will allow backwards compatibility for a range of functions, but there are also other ways of handling these situations.
You can fork your code based on the current Android version installed on the device by performing a check and using a different control element.
if(Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) {
\\ USE A TOGGLE BUTTON
} else {
\\USE SOMETHING ELSE!
}
This has disadvantages in branching your code to support different versions of Android.