Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Toggle button in Iphone Style

In android the Toggle buttons are looks like below -

Android

Can we modify this as Iphone style like below -

Iphone

And, Can we include the iphone functionality of toggle button like drag to toggle feature also.

How to complete this action? Thanks in Advance.

like image 752
Praveenkumar Avatar asked Mar 30 '12 06:03

Praveenkumar


People also ask

What does the toggle button look like for iPhone?

iOS uses toggle switches to show when settings are on or off. Toggle switches are white (when off) and green (when on). The On/Off Labels setting adds a 0 (zero) to the toggle switch when it is off and a 1 (one) when it is on.

How do I change the toggle button on my iPhone?

Go to Settings > Accessibility > Switch Control > Switches. Tap Add New Switch, then choose any of the following: External: Choose a Bluetooth switch or Made For iPhone (MFi) switch that plugs into the Lightning connector on iPhone. Screen: Tap the iPhone screen to activate the switch.

Which is toggle button?

A toggle button allows the user to change a setting between two states. You can add a basic toggle button to your layout with the ToggleButton object. Android 4.0 (API level 14) introduces another kind of toggle button called a switch that provides a slider control, which you can add with a Switch object.

What does toggle an app mean?

A toggle button allows a user to switch something on or off by clicking on it. Toggling can also refer to the action of switching back and forth between two things - switching between two social media accounts that have both been signed into on the same device for example.


1 Answers

Use SwitchCompat:

<!-- SwitchCompat -->     <androidx.appcompat.widget.SwitchCompat                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:checked="true"                 android:thumb="@drawable/thumb_selector"                 app:track="@drawable/track_selector"/>    <!-- thumb_selector.xml -->       <?xml version="1.0" encoding="utf-8"?>             <selector xmlns:android="http://schemas.android.com/apk/res/android">                 <item android:state_checked="false">                     <shape android:shape="oval">                         <solid android:color="@android:color/white" />                         <size android:width="20dp" android:height="20dp" />                         <stroke android:width="2dp" android:color="#0000ffff" />                     </shape> <!-- shape circle -->                 </item>             </selector>   <!-- track_selector.x --> <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android">      <item android:state_checked="true">         <shape android:shape="rectangle">             <size android:width="36dp" android:height="20dp"/>             <solid android:width="1dp" android:color="@android:color/holo_orange_dark"/>             <corners android:radius="50dp"/>         </shape>     </item>      <item android:state_checked="false">         <shape android:shape="rectangle">             <size android:width="36dp" android:height="20dp"/>             <solid android:width="1dp" android:color="@android:color/darker_gray"/>             <corners android:radius="50dp"/>         </shape>       </item>  </selector> 

toggle button screenshot

like image 181
Thắng Avatar answered Sep 23 '22 20:09

Thắng