jest miły wykład na ten temat z Google IO 2012 (starting at slide 32)
tu s szczegółowy przykład:
Utwórz osobny plik XML układu dla wersji ICS +, umieszczając go w/res/layout-v14. Uzyskana struktura pliku będzie wyglądać następująco:
res/layout
- mainlayout.xml
- compound_button.xml
res/layout-v14
- compound_button.xml
Android będzie wtedy szukać zasobów w katalogu layout-v14, gdy aplikacja jest uruchomiona na V14 lub wyższa.
Umieść to w mainlayout.xml że będzie ciągnąć w odnośnym compound_button.xml gdy aplikacja jest prowadzony:
<include layout="@layout/compound_button" />
dla pre 4,0 układ Chcemy wyboru, więc tworzenie/Układ/compound_button. xml jako seryjnej następująco:
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" >
<CheckBox
android:id="@+id/enabled"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enable" />
</merge>
a następnie przez układ 4.0+ chcemy przełącznika, więc utworzyć /layout-v14/compound_button.xml jako seryjnej następująco:
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" >
<Switch
android:id="@+id/enabled"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enable"
tools:ignore="NewApi" />
</merge>
Oczywiście, należy pamiętać, aby ustawić minimalną i cele odpowiednio:
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="14" />
Sprawdź rozwiązanie tutaj: http://stackoverflow.com/questions/9920709/use-android-4-0-styled-toggle-button/15640365#15640365 – dberm22