成都創(chuàng)新互聯(lián)公司專(zhuān)業(yè)為企業(yè)提供田林網(wǎng)站建設(shè)、田林做網(wǎng)站、田林網(wǎng)站設(shè)計(jì)、田林網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)與制作、田林企業(yè)網(wǎng)站模板建站服務(wù),十載田林做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。
上面布局中放了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"><!-- 畫(huà)矩形 --> <!--邊框色--> <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開(kāi)始畫(huà)線,需配合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í)或者工作能帶來(lái)一定的幫助,同時(shí)也希望多多支持創(chuàng)新互聯(lián)!
文章名稱(chēng):AndroidView背景選擇器編寫(xiě)技巧
標(biāo)題路徑:http://muchs.cn/article46/ighghg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站設(shè)計(jì)、商城網(wǎng)站、域名注冊(cè)、App設(shè)計(jì)、搜索引擎優(yōu)化、面包屑導(dǎo)航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)