Slide Toggle for Android

后端 未结 4 1001
醉酒成梦
醉酒成梦 2020-11-30 03:38

Anyone know of any open source implementation of a slide toggle for android. The default android toggle(ToggleButton) is not pretty. I am looking for anything similar to iOS

相关标签:
4条回答
  • 2020-11-30 03:42

    you can use the sliding drawer widget in android to have a sliding toggle switch. you just have to "slice" the ios toggle images into3 parts, one for the handle, one for the sliding drawer background and one for the content part. then put an image on top of it like a frame to give you the "round edges"

    here's what i've come up with: XML Layout

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
        <FrameLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="100dp" >
            <SlidingDrawer
                android:id="@+id/slidingDrawer1"
                android:layout_width="154dp"
                android:layout_height="54dp"
                android:background="@drawable/ios_retina_toggle_on_full"
                android:content="@+id/content"
                android:handle="@+id/handle"
                android:orientation="horizontal" >
                <ImageButton
                    android:id="@+id/handle"
                    android:layout_width="54dp"
                    android:layout_height="54dp"
                    android:background="#00000000"
                    android:src="@drawable/ios_retina_toggle_button" />
                <ImageView
                    android:id="@+id/content"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/ios_retina_toggle_off" />
            </SlidingDrawer>
            <ImageView
                android:id="@+id/imageView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ios_retina_toggle_frame" />
        </FrameLayout>
    </LinearLayout>
    

    ios_retina_toggle_on_full
    ios_retina_toggle_on_full.png

    ios_retina_toggle_button
    ios_retina_toggle_button.png

    ios_retina_toggle_off
    ios_retina_toggle_off.png

    ios_retina_toggle_frame
    ios_retina_toggle_frame.png

    and finally a screenshot of how it looked on the emulator on a 3.7 WVGA screen running gingerbread: enter image description here

    0 讨论(0)
  • 2020-11-30 03:42

    You can try using ToggleButton specifying your own drawables for its states.

    0 讨论(0)
  • iOS does not seem to have a "slide toggle", at least under that name, based on a Google search. And, you did not provide an image (or a link to an image) of what you want.

    Android 4.0 added a Switch that you might be able to backport to earlier versions. You will see samples of it in the API Demos app on your emulator:

    enter image description here

    0 讨论(0)
  • 2020-11-30 04:03

    We can try using seekbar with custom drawables and thumb, setting the max value to 1 and min to 0. we can add animations for sliding effect

    0 讨论(0)
提交回复
热议问题