SwitchButton的用法

來源:互聯網
上載者:User

1、switchbutton是項目開發中常用的開關控制項,可直接引用系統中的switchbutton,剛剛寫了一個小demo,研究了一下switchbutton中的一些常用屬性:

swThumbDrawable: drawable of thumb(按鈕的映像) swThumb_margin: set inner margin between thumb and edges swThumb_marginLeft/Top/Bottom/Right: set margin for specific edge swThumb_width: set the width of thumb, probably used for gradient drawable(按鈕的寬) swThumb_height: set the height of thumb(按鈕的高) swThumbColor: like the onColor(按鈕的顏色,預設為灰色,開啟時根據類型所定) swMeasureFactor: factor limit the minimum width equals almost (the height of thumb * measureFactor)(拇指高度) swTextOn:按鈕開始時顯示的內容 swTextOff:按鈕關閉的時顯示的內容 swBackColor:開關背景色 swBackDrawable:開關背景圖片 2、自己寫的小demo:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    tools:context="com.example.wls.myswitchbutton.MainActivity">    <com.alanapi.switchbutton.SwitchButton        android:id="@+id/switchButton1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_margin="10dp"        />    <com.alanapi.switchbutton.SwitchButton        android:id="@+id/switchButton2"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_margin="10dp"        app:swThumbHeight="30dp"        app:swThumbWidth="30dp"        />    <com.alanapi.switchbutton.SwitchButton        android:id="@+id/switchButton3"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_margin="10dp"        app:swThumbHeight="30dp"        app:swThumbWidth="30dp"        app:swThumbColor="#fff"        app:swBackColor="@color/radiocolor"/>    <com.alanapi.switchbutton.SwitchButton        android:id="@+id/switchButton4"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_margin="10dp"        app:swThumbHeight="30dp"        app:swThumbWidth="30dp"        app:swTextOn="ON"        app:swTextOff="OFF"        style="@style/SwitchButtonDefault"/>    <com.alanapi.switchbutton.SwitchButton        android:id="@+id/switchButton5"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_margin="10dp"        app:swThumbHeight="30dp"        app:swThumbWidth="30dp"        app:swTextOn="ON"        app:swTextOff="OFF"        style="@style/SwitchButtonFlyme"/>    <com.alanapi.switchbutton.SwitchButton        android:id="@+id/switchButton6"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_margin="10dp"        app:swThumbHeight="30dp"        app:swThumbWidth="30dp"        app:swTextOn="ON"        app:swTextOff="OFF"        style="@style/SwitchButtonIOS"/>    <com.alanapi.switchbutton.SwitchButton        android:id="@+id/switchButton7"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_margin="10dp"        app:swThumbHeight="30dp"        app:swThumbWidth="30dp"        app:swTextOn="ON"        app:swTextOff="OFF"        style="@style/SwitchButtonMD"/>    <com.alanapi.switchbutton.SwitchButton        android:id="@+id/switchButton8"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_margin="10dp"        app:swThumbHeight="30dp"        app:swThumbWidth="30dp"        app:swTextOn="ON"        app:swTextOff="OFF"        style="@style/SwitchButtonMiui"/></LinearLayout>
上面一系列SwitButton所對應的形式如圖所示:

   

其中第三個按鈕中XML中的Color如下:

<selector xmlns:android="http://schemas.android.com/apk/res/android">    <item android:color="#0757ec" android:state_checked="true"/>    <item android:color="#AAAAAA" android:state_checked="false"/>
這裡供上源碼地址: SwitchButton

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.