圓形背景圖標 (button)省容,點擊變色抖拴,簡單實現(xiàn)

如圖 實現(xiàn)右側上傳button,點擊整體變色


Screenshot_20191211-165118_FileManager.jpg

核心代碼

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="true">
        <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
            <item>
                <shape xmlns:android="http://schemas.android.com/apk/res/android"
                    android:shape="oval"
                    android:useLevel="false">
                    <solid android:color="#26000000" />
                    />
                </shape>
            </item>
            <item android:drawable="@drawable/cloud_upload_pressed" />
        </layer-list>
    </item>

    <item android:state_pressed="false">
        <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
            <item>
                <shape xmlns:android="http://schemas.android.com/apk/res/android"
                    android:shape="oval"
                    android:useLevel="false">
                    <solid android:color="#8d000000" />
                    />
                </shape>
            </item>
            <item android:drawable="@drawable/cloud_upload" />
        </layer-list>
    </item>
</selector>

使用簡單

<TextView
        android:id="@+id/videoUpload"
        android:layout_width="50dp"
        android:layout_height="50dp"
        ..........
        android:background="@drawable/upload_bg"
        android:clickable="true" 
        android:onClick="uploadTo..."/>

注意點:
透明背景圖片腥椒,圖片應留有一定padding

shape

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape=["rectangle" | "oval" | "line" | "ring"] >
    <corners
        android:radius="integer"
        android:topLeftRadius="integer"
        android:topRightRadius="integer"
        android:bottomLeftRadius="integer"
        android:bottomRightRadius="integer" />
    <gradient
        android:angle="integer"
        android:centerX="integer"
        android:centerY="integer"
        android:centerColor="integer"
        android:endColor="color"
        android:gradientRadius="integer"
        android:startColor="color"
        android:type=["linear" | "radial" | "sweep"]
        android:useLevel=["true" | "false"] />
    <padding
        android:left="integer"
        android:top="integer"
        android:right="integer"
        android:bottom="integer" />
    <size
        android:width="integer"
        android:height="integer" />
    <solid
        android:color="color" />
    <stroke
        android:width="integer"
        android:color="color"
        android:dashWidth="integer"
        android:dashGap="integer" />
</shape>

單純背景色drawable

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item  android:state_pressed="true">
        <shape
            android:shape="rectangle"
            android:useLevel="false">
            <solid android:color="#26000000" />
        </shape>
    </item>
    <item android:state_hovered="true">
       <shape
        android:shape="rectangle"
        android:useLevel="false">
        <solid android:color="#26000000" />
    </shape>
    </item>
    <item>
        <shape
            android:shape="rectangle"
            android:useLevel="false">
        <solid android:color="#00000000" />
        </shape>
    </item>
</selector>

單純圖片focus變換

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true"  android:drawable="@drawable/cloud_upload_pressed"/>
    <item android:state_pressed="false" android:drawable="@drawable/cloud_upload"/>
</selector>

單純顏色color

<selector xmlns:android="http://schemas.android.com/apk/res/android">   
<item android:state_selected="true" android:color="#000" />   
<item android:state_focused="true" android:color="#000" />   
<item android:state_pressed="true" android:color="#000" />
<item android:color="#FFF" />   
</selector> 
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末阿宅,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子笼蛛,更是在濱河造成了極大的恐慌洒放,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,755評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件滨砍,死亡現(xiàn)場離奇詭異往湿,居然都是意外死亡,警方通過查閱死者的電腦和手機惋戏,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,305評論 3 395
  • 文/潘曉璐 我一進店門领追,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人响逢,你說我怎么就攤上這事绒窑。” “怎么了舔亭?”我有些...
    開封第一講書人閱讀 165,138評論 0 355
  • 文/不壞的土叔 我叫張陵些膨,是天一觀的道長散罕。 經(jīng)常有香客問我,道長傀蓉,這世上最難降的妖魔是什么欧漱? 我笑而不...
    開封第一講書人閱讀 58,791評論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮葬燎,結果婚禮上误甚,老公的妹妹穿的比我還像新娘。我一直安慰自己谱净,他們只是感情好窑邦,可當我...
    茶點故事閱讀 67,794評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著壕探,像睡著了一般冈钦。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上李请,一...
    開封第一講書人閱讀 51,631評論 1 305
  • 那天瞧筛,我揣著相機與錄音,去河邊找鬼导盅。 笑死较幌,一個胖子當著我的面吹牛,可吹牛的內容都是我干的白翻。 我是一名探鬼主播乍炉,決...
    沈念sama閱讀 40,362評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼滤馍!你這毒婦竟也來了岛琼?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 39,264評論 0 276
  • 序言:老撾萬榮一對情侶失蹤巢株,失蹤者是張志新(化名)和其女友劉穎槐瑞,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體纯续,經(jīng)...
    沈念sama閱讀 45,724評論 1 315
  • 正文 獨居荒郊野嶺守林人離奇死亡随珠,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 37,900評論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了猬错。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片窗看。...
    茶點故事閱讀 40,040評論 1 350
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖倦炒,靈堂內的尸體忽然破棺而出显沈,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 35,742評論 5 346
  • 正文 年R本政府宣布拉讯,位于F島的核電站涤浇,受9級特大地震影響,放射性物質發(fā)生泄漏魔慷。R本人自食惡果不足惜只锭,卻給世界環(huán)境...
    茶點故事閱讀 41,364評論 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望院尔。 院中可真熱鬧蜻展,春花似錦、人聲如沸邀摆。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,944評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽栋盹。三九已至施逾,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間例获,已是汗流浹背汉额。 一陣腳步聲響...
    開封第一講書人閱讀 33,060評論 1 270
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留躏敢,地道東北人闷愤。 一個月前我還...
    沈念sama閱讀 48,247評論 3 371
  • 正文 我出身青樓,卻偏偏與公主長得像件余,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子遭居,可洞房花燭夜當晚...
    茶點故事閱讀 44,979評論 2 355

推薦閱讀更多精彩內容