亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

基于android背景選擇器selector的用法匯總

 更新時(shí)間:2013年06月14日 16:43:30   作者:  
本篇文章是對(duì)android背景選擇器selector的用法進(jìn)行了詳細(xì)的總結(jié)與分析,需要的朋友參考下
一.創(chuàng)建xml文件,位置:drawable/xxx.xml,同目錄下記得要放相關(guān)圖片
復(fù)制代碼 代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- 沒(méi)有焦點(diǎn)時(shí)的背景圖片 -->
    <item android:drawable="@drawable/handle_normal" android:state_enabled="true" android:state_window_focused="false"/>
    <!-- 觸摸模式按下時(shí)的背景圖片 -->
    <item android:drawable="@drawable/handle_pressed" android:state_pressed="true"/>
    <item android:drawable="@drawable/handle_focused" android:state_enabled="true" android:state_focused="true"/>
    <item android:drawable="@drawable/handle_normal" android:state_enabled="true"/>
    <!-- 獲得焦點(diǎn)時(shí)的圖片背景 -->
    <item android:drawable="@drawable/handle_focused" android:state_focused="true"/>
    <!--
    android:state_selected是選中
 android:state_focused是獲得焦點(diǎn)
 android:state_pressed是點(diǎn)擊
 android:state_enabled是設(shè)置是否響應(yīng)事件,指所有事件
    -->
</selector>

.使用xml文件:
1.方法一:listview中配置android:listSelector="@drawable/xxx
或者在listviewitem中添加屬性android
background="@drawable/xxx"

2.方法二:Drawable drawable = getResources().getDrawable(R.drawable.xxx);  
ListView.setSelector(drawable);
但是這樣會(huì)出現(xiàn)列表有時(shí)候?yàn)楹诘那闆r,需要加上:android:cacheColorHint="@android:color/transparent"
使其透明。
相關(guān)屬性:

android:state_selected是選中
android:state_focused
是獲得焦點(diǎn)
android:state_pressed
是點(diǎn)擊
android:state_enabled
是設(shè)置是否響應(yīng)事件,指所有事件

根據(jù)這些狀態(tài)同樣可以設(shè)置buttonselector效果。也可以設(shè)置selector改變button中的文字狀態(tài)。
以下是配置button中的文字效果:
drawable/button_font.xml

復(fù)制代碼 代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_selected="true" android:color="#FFF" />
    <item android:state_focused="true" android:color="#FFF" />
    <item android:state_pressed="true" android:color="#FFF" />
    <item android:color="#000" />
</selector>

Button還可以實(shí)現(xiàn)更復(fù)雜的效果,例如漸變
drawable/button_color.xml
復(fù)制代碼 代碼如下:

<SPAN style="COLOR: #330033"><?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">         /
<item android:state_pressed="true">//定義當(dāng)button 處于pressed 狀態(tài)時(shí)的形態(tài)。
                <shape>
                <gradient  android:startColor="#8600ff" />
                      <stroke   android:width="2dp" android:color="#000000" />
                       <corners android:radius="5dp" /> 
                       <padding android:left="10dp" android:top="10dp"
                                android:bottom="10dp" android:right="10dp"/> 
                 </shape>
</item>
<item android:state_focused="true">//定義當(dāng)button獲得 focus時(shí)的形態(tài)
                 <shape>
                       <gradient android:startColor="#eac100"/>
                       <stroke android:width="2dp" android:color="#333333"  color="#ffffff"/>
                       <corners android:radius="8dp" />  
                       <padding android:left="10dp" android:top="10dp"
                                android:bottom="10dp" android:right="10dp"/>                  
                </shape>
 </item>
</selector></SPAN><SPAN style="COLOR: #ff0000"> </SPAN>

最后,需要在包含 button的xml文件里添加兩項(xiàng)。例如main.xml 文件,需要在<Button />里加兩項(xiàng)android:focusable="true" android:background="@drawable/button_color"這樣就把drawale/button_color.xml文件與這個(gè)控件關(guān)聯(lián)起來(lái)了。

相關(guān)文章

  • Android應(yīng)用中實(shí)現(xiàn)手勢(shì)控制圖片縮放的完全攻略

    Android應(yīng)用中實(shí)現(xiàn)手勢(shì)控制圖片縮放的完全攻略

    這篇文章主要介紹了Android應(yīng)用中實(shí)現(xiàn)手勢(shì)控制圖片縮放的完全攻略,采用了Matrix矩陣的方法,實(shí)例講解了包括觸摸點(diǎn)設(shè)置與各種沖突的處理等方面,相當(dāng)全面,需要的朋友可以參考下
    2016-04-04
  • Android實(shí)現(xiàn)歡迎界面停留3秒效果

    Android實(shí)現(xiàn)歡迎界面停留3秒效果

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)歡迎界面停留3秒效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-02-02
  • Android編程之Animation動(dòng)畫(huà)詳解

    Android編程之Animation動(dòng)畫(huà)詳解

    這篇文章主要介紹了Android編程之Animation動(dòng)畫(huà)具體用法,結(jié)合實(shí)例非常詳細(xì)的總結(jié)分析了Android中Animation動(dòng)畫(huà)所涉及的相關(guān)知識(shí)點(diǎn)與動(dòng)畫(huà)具體實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2016-01-01
  • Flutter使用AnimatedBuilder實(shí)現(xiàn)動(dòng)效復(fù)用

    Flutter使用AnimatedBuilder實(shí)現(xiàn)動(dòng)效復(fù)用

    Animation和AnimationWidget都是將組件和動(dòng)畫(huà)一起完成的。有些時(shí)候,我們只是想動(dòng)效復(fù)用,而不關(guān)心組件構(gòu)建,這個(gè)時(shí)候就可以使用 AnimatedBuilder了。本文詳細(xì)講解了AnimatedBuilder的使用,需要的可以參考一下
    2022-04-04
  • Android實(shí)現(xiàn)單行標(biāo)簽流式布局

    Android實(shí)現(xiàn)單行標(biāo)簽流式布局

    這篇文章主要為大家詳細(xì)介紹了Android單行標(biāo)簽流式布局,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-09-09
  • Android仿google now效果的呼吸按鈕

    Android仿google now效果的呼吸按鈕

    這篇文章主要為大家詳細(xì)介紹了Android仿google now效果的呼吸按鈕簡(jiǎn)單實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-08-08
  • android平臺(tái)HttpGet、HttpPost請(qǐng)求實(shí)例

    android平臺(tái)HttpGet、HttpPost請(qǐng)求實(shí)例

    出自網(wǎng)絡(luò)搜索引擎巨頭的Android平臺(tái),其對(duì)網(wǎng)絡(luò)的支持自然不用多說(shuō),在Android SDK中已經(jīng)集成了Apache的HttpClient模塊。使用HttpClient模塊,我們就可以使用HTTP協(xié)議進(jìn)行網(wǎng)絡(luò)連接了
    2014-05-05
  • Android中使用ListView繪制自定義表格技巧分享

    Android中使用ListView繪制自定義表格技巧分享

    使用ListView繪制自定義的表格有朋友嘗試過(guò)沒(méi)有,下面為大家分享下要實(shí)現(xiàn)下圖的效果有幾個(gè)方面,參照著這幾點(diǎn)做了個(gè)簡(jiǎn)單的實(shí)現(xiàn)不是問(wèn)題好了,話不多說(shuō)看代碼
    2013-06-06
  • Android Studio 導(dǎo)入開(kāi)源項(xiàng)目的正確姿勢(shì)及注意事項(xiàng)

    Android Studio 導(dǎo)入開(kāi)源項(xiàng)目的正確姿勢(shì)及注意事項(xiàng)

    這篇文章主要介紹了Android Studio 導(dǎo)入開(kāi)源項(xiàng)目的正確姿勢(shì)及注意事項(xiàng),需要的朋友參考下吧
    2018-03-03
  • Android中模仿抖音加載框之兩顆小球轉(zhuǎn)動(dòng)效果

    Android中模仿抖音加載框之兩顆小球轉(zhuǎn)動(dòng)效果

    這篇文章主要介紹了Android仿抖音加載框之兩顆小球轉(zhuǎn)動(dòng)控件,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2018-09-09

最新評(píng)論