I want to have the Lollipop style switch button for my app:
How could I im
To have the Lollipop style switch button on older versions of android you should use SwitchCompat in layout xml file
<android.support.v7.widget.SwitchCompat
android:id="@+id/compatSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
and also in java file
SwitchCompat switchCompat = (SwitchCompat) findViewById(R.id.compatSwitch);
API 24 on off switch
<android.support.v7.widget.SwitchCompat
android:id="@+id/switch1"
android:layout_alignBottom="@+id/textView3"
android:layout_alignEnd="@+id/input_layout_password"
android:layout_alignRight="@+id/input_layout_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
I think what you need is in that library
what this library does is to allow you to create material design switch button like in andorid 5.0
https://github.com/kyleduo/SwitchButton
We are using SwitchCompact in lollipop version or either you can use Updated lolliopop version its better
<android.support.v7.widget.SwitchCompat
android:id="@+id/compatSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/switch2"
android:layout_alignLeft="@+id/switch2"
android:layout_alignStart="@+id/switch2"
android:layout_marginTop="39dp" />
In order to resolve old type switch
switch_old
`
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorAccent">@color/colorAccent</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
</style>`
and it resolve switch with latest material design.
There is a great article on the Android Developers Blog that discusses how to use material design on pre-Lollipop devices: http://android-developers.blogspot.com/2014/10/appcompat-v21-material-design-for-pre.html
To more specifically answer your question, you can use the Lollipop style switch for older versions by using the SwitchCompat
API: https://developer.android.com/reference/android/support/v7/widget/SwitchCompat.html