国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android 自定義Button控件實現按鈕點擊變色

2019-12-12 04:48:36
字體:
來源:轉載
供稿:網友

效果圖如下所示:

一、shape 樣式:(在drawable新建--》new--》Drawable resource file 在父級標簽selector添加Item )

<?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"><solid android:color="#73c4f3" /><stroke android:width="2dp" android:color="#ffffff" /><corners android:radius="20dp" /><padding android:bottom="5dp" android:left="10dp" android:right="10dp" android:top="5dp" /><gradient android:angle="270" android:endColor="#8accf2" android:startColor="#8accf2" android:type="sweep" /></shape><shape><solid android:color="#3fb3f6" /><stroke android:width="2dp" android:color="#ffffff" /><corners android:radius="20dp" /><padding android:bottom="5dp" android:left="10dp" android:right="10dp" android:top="5dp" /></shape></item></selector>

二、style 樣式:

<style name="rectangle"><item name="android:layout_width">match_parent</item><item name="android:layout_height">wrap_content</item><item name="android:textSize">15sp</item><item name="android:textColor">#ffffff</item><item name="android:background">@drawable/buttonclickstyle</item></style>

三、Button控件調用style樣式:

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:paddingBottom="@dimen/activity_vertical_margin"android:paddingLeft="@dimen/activity_horizontal_margin"android:paddingRight="@dimen/activity_horizontal_margin"android:paddingTop="@dimen/activity_vertical_margin"tools:context="com.example.ly.blogtest.MainActivity"><Buttonandroid:id="@+id/button"style="@style/rectangle"android:text="@string/btn1" /></RelativeLayout>

----------------------------------按鈕點擊變色-----------------------------------------------------

----------------------------------item屬性標記------------------------------

android:state_pressed 是否按下,如一個按鈕觸摸或者點擊。

android:state_focused 是否取得焦點,比如用戶選擇了一個文本框。

android:state_hovered 光標是否懸停,通常與focused state相同,它是4.0的新特性

android:state_selected 被選中,它與focus state并不完全一樣,如一個list view 被選中的時候,它里面的各個子組件可能通過方向鍵,被選中了。

android:state_checkable 組件是否能被check。如:RadioButton是可以被check的。

android:state_checked 被checked了,如:一個RadioButton可以被check了。

android:state_enabled 能夠接受觸摸或者點擊事件

android:state_activated 被激活

android:state_window_focused

應用程序是否在前臺,當有通知欄被拉下來或者一個對話框彈出的時候應用程序就不在前臺了

注意:如果有多個item,那么程序將自動從上到下進行匹配,最先匹配的將得到應用。(不是通過最佳匹配)

如果一個item沒有任何的狀態說明,那么它將可以被任何一個狀態匹配。

----------------------------------item屬性標記------------------------------

以上所述是小編給大家介紹的Android 自定義Button控件實現按鈕點擊變色,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 进贤县| 聂拉木县| 囊谦县| 阜新| 孟津县| 陕西省| 色达县| 芜湖县| 图木舒克市| 南宁市| 卓资县| 苍溪县| 嵩明县| 佛教| 安泽县| 科技| 东平县| 准格尔旗| 特克斯县| 贵州省| 富裕县| 呈贡县| 平湖市| 丽江市| 南宫市| 高要市| 永靖县| 平邑县| 长垣县| 宾阳县| 湟中县| 萨迦县| 叙永县| 天门市| 连州市| 诏安县| 濮阳市| 乌拉特中旗| 韶关市| 西乌珠穆沁旗| 博兴县|