How to implement the feature introduced in higher version to lower version in Android

StackOverflow https://stackoverflow.com/questions/18975008

  •  29-06-2022
  •  | 
  •  

Question

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.

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top