Aquí es un ejemplo de SwitchCompat
primero que debe hacer Asegúrese de agregar estas líneas a su build.gradle y luego sincronización.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
}
En segundo lugar crear una actividad de la muestra, en mi caso lo llamaré SwitchActivity.java.
public class SwitchActivity extends ActionBarActivity {
SwitchCompat mySwitch = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_switch);
// here is your switch
mySwitch = (SwitchCompat)findViewById(R.id.myswitch);
}
.....
}
Por último cree su diseño, en mi caso lo llamaré activity_switch.xml.
<RelativeLayout 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"
tools:context="com.neoecosystem.samplex.SwitchActivity">
<android.support.v7.widget.SwitchCompat
android:id="@+id/myswitch"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
</RelativeLayout>
enlace ya no funciona – mprabhat
Qué pasa con aquellos: https://github.com/yongjhih/SwitchPreferenceCompat https://github.com/ankri/SwitchCompatLibrary https: // github.com/BoD/android-switch-backport –