devanshu_kaushik
devanshu_kaushik

Reputation: 969

Supporting a different look for the same View for the corresponding API level in Android

I have built a test application in Android with minimum API level as 8 in which I want to implement the following :

I have a toggle button which looks somewhat like this :

enter image description here

This as you know is the default design of toggle buttons in API level 8. But I want my UI to be adaptive to the API level the application is running in. So in case the same app is running on Ice Cream Sandwhich (API level 15) , the same toggle button should look like this :

enter image description here

Does android provide any means to support this feature without building different a apk for each API level?

Upvotes: 2

Views: 625

Answers (1)

Waza_Be
Waza_Be

Reputation: 39538

Edit

  • You need to work with sdk level 16 (or the latest), so the Switch class will be recognized
  • set android:minSdkVersion to 8 in the manifest
  • work with folders like stated below:

You have to use different layout that you will put in different layout folder.

For the api level 8 (and above), put it in

/res/layout-v8 and use the ToggleButton class: http://developer.android.com/guide/topics/ui/controls/togglebutton.html

For the level 15:

/res/layout-v15 and use a Switch class.

Good readings for you: http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources

Upvotes: 3

Related Questions