-2

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

user3309272
  • 67
  • 1
  • 1
  • 4

3 Answers3

0

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?

Community
  • 1
  • 1
0

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

Blundell
  • 75,855
  • 30
  • 208
  • 233
0

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

Community
  • 1
  • 1
Hamidreza Samadi
  • 637
  • 1
  • 7
  • 24