My application will run on api level 9 devices or higher. Now i have a toggle_button on one of the layouts. I want to change this toggle button to switcher if the device is apilevel 14 or higher. How can i implement this? Sorry for my english.
Asked
Active
Viewed 1,031 times
2 Answers
2
If you are creating the content/pages in xml, simply copy your xml with same name but to the layout-v14
folder. Then change ToggleButton to SwitchButton, and Android will take care of rest :)
If you are coding it in jave, use:
if(Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH){
//Add Switch
}else{
//add toggle
}
And when you'll want to use both (when using defining in xml) with the same java code use:
CompoundButton bt_toggle= (CompoundButton) findViewById(R.id.some_button);
bt_toggle.setChecked(false);

Toumash
- 1,077
- 11
- 27
-
Thanks for answer. Can you advise some interesting library for supporting switchers in api level 9? – Valentin Baryshev Nov 24 '14 at 21:30
-
1http://ankri.de/switch-button-for-android-2-3-gingerbread/ Check this code out, for download click the .zip option above the code for implementing it, see http://stackoverflow.com/questions/5514281/how-to-use-own-view-in-layout – Toumash Nov 24 '14 at 21:32
-
this is for api level 10 :) – Valentin Baryshev Nov 24 '14 at 21:35
-
1This is your decision, Android support library weights around 1MB after compilation and proGuard run. I dont know anything better, but im not expert – Toumash Nov 24 '14 at 21:41
0
I have found a solution! link
It just adds a support library. And you can use switchers from api-level7!

Valentin Baryshev
- 2,195
- 3
- 15
- 24