可以使用滑動抽屜部件在android系統有一個滑動切換開關。您只需將ios切換圖像「切片」爲3個部分,一個用於手柄,一個用於滑動抽屜背景,另一個用於內容部分。然後把圖像放在它的上面像一個框架給你「圓緣」
這裏就是我想出了: XML佈局
<?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_button
ios_retina_toggle_off
ios_retina_toggle_frame
最後一個它是如何看在模擬器上3截圖。7 WVGA屏幕運行薑餅:
我結束了背移植4.0代碼到2.2.2。我還爲小部件添加了一些新的屬性,以適應我正在開發的項目。雖然外觀與iOS或Android不完全相同,但可以使用drawable輕鬆更改。該項目託管在github上 https://github.com/pellucide/Android-Switch-Demo-pre-4.0/tree/master/android-switch-demo – pellucide 2012-05-30 09:40:31
對不起,我之前沒有看到這個,因爲我只是做了同樣的事情:我支持Switch類與2.2一起工作。結果在這裏:https://github.com/BoD/android-switch-backport - 我希望它可以是有用的,它與你自己的端口稍有不同,因爲它包含了ICS的'標準'drawables。 – BoD 2012-06-12 01:16:17
哇!做得好。我也希望在剝皮按鈕之前看到了這一點。 http://stackoverflow.com/questions/9920709/use-android-4-0-styled-toggle-button/15640365#15640365 – dberm22 2013-03-26 17:08:05