hi guys i am working on switch wants to implement. The real problem is switch is available in API 14 and wants to implement same functionality for below level.one solution is to use bullets for on and off option for below 14 level.another solution for above API 14 to use to use switch but the main problem is how i check API level at run time in layout file. Thanks in advance
-
4try and describe your problem more clearly, now it doesn't make much sense what you trying to do – Goran Horia Mihail Dec 31 '14 at 16:41
3 Answers
it is not possible to check the version through XML. you have to do it through the java code, you can get the API level with Build.VERSION.RELEASE
you can see another question here: Programmatically obtain the Android API level of a device?

- 1
- 1
You can use different resources buckets to "check the api level for the layout file:"
http://developer.android.com/training/basics/supporting-devices/screens.html#create-layouts
However where this example talks about different screen sizes you want different API versions.
For example:
MyProject/
res/
layout/
main.xml
layout-v14/
main.xml
gives you a different main.xml
for ICS and above

- 75,855
- 30
- 208
- 233
you can create two different layout
and check api level
in java code. then if api level
less than 14
use one of layouts
and if greater than 14
use another layout
.
for checking api level
in java see this

- 1
- 1

- 637
- 1
- 7
- 24