欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android開發(fā)手冊自定義Switch開關(guān)按鈕控件

 更新時(shí)間:2022年06月10日 16:47:47   作者:芝麻粒兒  
這篇文章主要為大家介紹了Android開發(fā)手冊自定義Switch開關(guān)按鈕控件的示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

??自定義Switch外觀

外觀定制這塊屬于基操了,我們利用屬性 android:track 和 android:thumb 定制 Switch 的背景圖片和滑塊圖片,UI那能直接切圖肯定做起來更快,此方式實(shí)現(xiàn)極其簡單指定圖片就行,所以今天我們實(shí)操的是自定義drawable的形式。

布局樣式

<Switch
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:thumb="@drawable/selector_switch_thumb"
    android:layout_margin="16dp"
    android:track="@drawable/selector_switch_track" />

Drawable代碼

<?xml version="1.0" encoding="utf-8"?><!--switch的自定義軌道-->
<!--selector_switch_track.xml文件-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/track_on" android:state_checked="true" />
    <item android:drawable="@drawable/track_off" android:state_checked="false" />
</selector>
<?xml version="1.0" encoding="utf-8"?><!--switch的自定義圓鈕-->
<!--selector_switch_thumb.xml文件-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/thumb_on" android:state_checked="true" />
    <item android:drawable="@drawable/thumb_off" android:state_checked="false" />
</selector>
<?xml version="1.0" encoding="utf-8"?>
<!--track_on.xml文件-->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#BB00FF00" />
    <!-- 這個(gè)是用來實(shí)現(xiàn)軌道高度小于圓鈕高度的,值越大軌道越細(xì)-->
    <!-- 同理,若thumb有stroke,track沒有,可實(shí)現(xiàn)圓鈕在軌道里的偽效果-->
    <stroke
        android:width="8dp"
        android:color="#00000000" />
    <corners android:radius="20dp" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<!--track_off.xml文件-->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#E4E4E4" />
    <!-- 這個(gè)是用來實(shí)現(xiàn)軌道高度小于圓鈕高度的,值越大軌道越細(xì)-->
    <stroke
        android:width="8dp"
        android:color="#00000000" />
    <corners android:radius="20dp" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<!--thumb_on.xml文件-->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <solid android:color="#FFFF00" />
    <size
        android:width="20dp"
        android:height="20dp" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<!--thumb_off.xml文件-->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <solid android:color="#AAAAAA" />
    <size
        android:width="20dp"
        android:height="20dp" />
</shape>

要想實(shí)現(xiàn)下圖效果:

就是小空在代碼中注釋所述,在開關(guān)按鈕上增加一個(gè)透明的邊框,軌道的高度會(huì)自動(dòng)變化。

除了Switch還有另一個(gè)開關(guān)ToggleButton,該控件無thumb和track,相比Switch缺少了滑動(dòng)的動(dòng)畫效果。在使用上和Switch基本一致,同樣可以自定義。

以上就是Android開發(fā)手冊自定義Switch開關(guān)按鈕控件的詳細(xì)內(nèi)容,更多關(guān)于Android開發(fā)自定義Switch控件的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • Android項(xiàng)目中使用HTTPS配置的步驟詳解

    Android項(xiàng)目中使用HTTPS配置的步驟詳解

    這篇文章主要給大家介紹了關(guān)于Android項(xiàng)目中使用HTTPS配置步驟的相關(guān)資料,文中介紹的非常詳細(xì),對大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起看看吧。
    2017-06-06
  • Android中WebView無法后退和js注入漏洞的解決方案

    Android中WebView無法后退和js注入漏洞的解決方案

    這篇文章主要介紹了Android中WebView無法后退和js注入漏洞解決方案,其中js注入主要針對安卓4.2及以下版本中WebView的漏洞,需要的朋友可以參考下
    2016-02-02
  • android多種滑動(dòng)沖突的解決方案

    android多種滑動(dòng)沖突的解決方案

    本篇文章主要介紹了android多種滑動(dòng)沖突的解決方案,解決方案主要有2種,外部攔截法 和內(nèi)部攔截法,有興趣的可以了解一下。
    2017-02-02
  • Android實(shí)現(xiàn)帶節(jié)點(diǎn)的進(jìn)度條

    Android實(shí)現(xiàn)帶節(jié)點(diǎn)的進(jìn)度條

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)帶節(jié)點(diǎn)的進(jìn)度條,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-03-03
  • Android開發(fā)疫情查詢app(實(shí)例代碼)

    Android開發(fā)疫情查詢app(實(shí)例代碼)

    這篇文章主要介紹了用Android開發(fā)一個(gè)疫情查詢的APP,文中代碼非常詳細(xì),供大家參考和學(xué)習(xí),感興趣的朋友可以了解下
    2020-06-06
  • Android如何跳轉(zhuǎn)到應(yīng)用商店的APP詳情頁面

    Android如何跳轉(zhuǎn)到應(yīng)用商店的APP詳情頁面

    最近做項(xiàng)目遇到這樣的需求,要求從App內(nèi)部點(diǎn)擊按鈕或鏈接,跳轉(zhuǎn)到應(yīng)用商店的某個(gè)APP的詳情頁面,怎么實(shí)現(xiàn)此功能呢?下面小編給大家分享Android如何跳轉(zhuǎn)到應(yīng)用商店的APP詳情頁面,需要的朋友參考下
    2017-01-01
  • 詳解如何在Android studio中更新sdk版本和build-tools版本

    詳解如何在Android studio中更新sdk版本和build-tools版本

    這篇文章主要介紹了如何在Android studio中更新sdk版本和build-tools版本,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-11-11
  • flutter輪子計(jì)劃之進(jìn)度條

    flutter輪子計(jì)劃之進(jìn)度條

    這篇文章主要為大家詳細(xì)介紹了flutter輪子計(jì)劃之進(jìn)度條,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-10-10
  • android adb實(shí)用命令小結(jié)

    android adb實(shí)用命令小結(jié)

    adb對于Android程序員來說在日常的工作中使用頻率很高,現(xiàn)將自己工作中常用的adb命令總結(jié)一下備忘,方便查詢,也供大家參考
    2017-04-04
  • Android實(shí)現(xiàn)隨手指移動(dòng)小球

    Android實(shí)現(xiàn)隨手指移動(dòng)小球

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)隨手指移動(dòng)小球,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-08-08

最新評論