1

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.

Avadhani Y
  • 7,566
  • 19
  • 63
  • 90
Sniper
  • 2,412
  • 11
  • 44
  • 49

1 Answers1

1

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.

CodeMonkey
  • 1,426
  • 1
  • 14
  • 32