Android View背景選擇器編寫技巧
- 在項(xiàng)目中選擇器的使用是非常多的,以下是本人在項(xiàng)目中的一些常用的背景選擇器的寫法
- 帶邊框下劃線背景選擇器效果圖:
上面布局中放了10個(gè)CheckBox,然后設(shè)置了CheckBox的背景圖片位,背景選擇器,同時(shí)設(shè)置了字體的顏色選擇器。
帶邊框下劃線背景選擇器代碼:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <!-- 選中狀態(tài) --> <item android:state_checked="true"> <!-- 設(shè)置層次背景 --> <layer-list> <!-- 底層 --> <item> <shape android:shape="rectangle"><!-- 畫矩形 --> <!--邊框色--> <stroke android:width="1dp" android:color="@color/gray27"/> <!-- 背景色 --> <solid android:color="@color/gray17"/> <!-- 圓角 --> <corners android:radius="3dp"/> </shape> </item> <!-- 上層 --> <item android:top="36.5dp"> <!-- top:距離頂部多少db開始畫線,需配合View的高度繪制 --> <shape android:shape="rectangle"> <solid android:color="@color/mainColor"/> </shape> </item> </layer-list> </item> <!-- 默認(rèn)狀態(tài) --> <item> <shape> <stroke android:width="1dp" android:color="@color/gray27"/> <solid android:color="@color/white"/> <corners android:radius="@dimen/radius"/> </shape> </item> </selector>
字體選擇器代碼:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="true" android:color="@color/mainColor" /> <item android:color="@color/textColor54" /> </selector>
邊框背景選擇器效果圖:
邊框背景選擇器實(shí)現(xiàn)代碼:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="true"> <shape > <stroke android:width="1dp" android:color="@color/mainColor"/> <solid android:color="@color/gray17"/> <!-- 圓角 --> <corners android:radius="@dimen/radius"/> </shape> </item> <item> <shape> <stroke android:width="1dp" android:color="@color/gray27"/> <solid android:color="@color/white"/> <corners android:radius="@dimen/radius"/> </shape> </item> </selector>
-- 不帶邊框下劃線背景選擇器效果圖:
不帶邊框下劃線背景選擇器實(shí)現(xiàn)代碼:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:state_checked="true"> <layer-list> <item android:top="36.5dp"> <shape android:shape="rectangle" > <solid android:color="@color/mainColor" /> </shape> </item> </layer-list> </item> <item android:drawable="@color/transColor" /> </selector>
以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時(shí)也希望多多支持腳本之家!
相關(guān)文章
在Android打包中區(qū)分測(cè)試和正式環(huán)境淺析
這篇文章主要給大家介紹了關(guān)于在Android打包中如何區(qū)分測(cè)試和正式環(huán)境的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起看看吧。2017-10-10Android數(shù)據(jù)加密之異或加密算法的實(shí)現(xiàn)方法
下面小編就為大家?guī)硪黄狝ndroid數(shù)據(jù)加密之異或加密算法的實(shí)現(xiàn)方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-10-10kotlin 官方學(xué)習(xí)教程之基礎(chǔ)語法詳解
這篇文章主要介紹了kotlin 官方學(xué)習(xí)教程之基礎(chǔ)語法詳解的相關(guān)資料,需要的朋友可以參考下2017-05-05Android?中?FrameLayout?布局及屬性的使用詳解
這篇文章主要介紹了Android?中?FrameLayout?布局及屬性的使用,FrameLayout?在實(shí)現(xiàn)簡(jiǎn)單布局時(shí)非常方便,特別適用于疊加式布局,如顯示疊加的圖層或浮動(dòng)按鈕等,需要的朋友可以參考下2024-03-03OpenGL ES正交投影實(shí)現(xiàn)方法(三)
這篇文章主要為大家詳細(xì)介紹了OpenGL ES正交投影的實(shí)現(xiàn)方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-05-05