1 Android 使用Vector XML文件創建矢量圖片資源 2 blog:http://blog.csdn.net/klxh2009/article/details/51121034 3 所需工具: 4 1、阿里巴巴矢量圖庫(http://www.iconfont.cn/) 5 2、GIMP(GNU Image Manipulation Program) 6 其中,GIMP我提供了兩種下載方式: 7 官網:http://www.gimp.org/ 8 百度網盤:http://pan.baidu.com/s/1sl9VnRZ 9 3、Android Studio 10 11 首先vector 標簽是一個drawable對象,所以是放在res/drawable目錄的。 12 1. 13 <vector android:height="24dp" //控件的寬高,必須設定的選項 14 android:width="24dp" 15 android:tint="@color/icon_huawei_color_click_selector"//取色器icon_huawei_color_click_selector.xml的引用(color selector) 16 android:viewportWidth="96.0" //畫布的寬高,必須設定的選項 17 android:viewportHeight="96.0" 18 xmlns:android="http://schemas.android.com/apk/res/android"> 19 <path android:fillColor="#007DFF" android:pathData="M15,46h58.8L45.9,18.1c-1.2,-1.2 -1.2,-3.1 0,-4.2c1.2,-1.2 3.1,-1.2 4.2,0l33,33c0.1,0.1 0.3,0.3 0.4,0.5c0,0.1 0.1,0.2 0.1,0.2c0.1,0.1 0.1,0.2 0.1,0.3c0,0.1 0.1,0.2 0.1,0.3c0,0.1 0.1,0.2 0.1,0.2c0,0.2 0.1,0.4 0.1,0.6l0,0l0,0c0,0.2 0,0.4 -0.1,0.6c0,0.1 0,0.2 -0.1,0.2c0,0.1 -0.1,0.2 -0.1,0.3c0,0.1 -0.1,0.2 -0.1,0.3c0,0.1 -0.1,0.2 -0.1,0.2c-0.1,0.2 -0.2,0.3 -0.4,0.5l-33,33c-1.2,1.2 -3.1,1.2 -4.2,0c-1.2,-1.2 -1.2,-3.1 0,-4.2L73.8,52H15c-1.7,0 -3,-1.3 -3,-3C12,47.3 13.3,46 15,46z"/> 20 </vector> 21 22 附加用法:<path android:fillColor="#00000000" 23 android:pathData="M34.88,48L13.12,25.58" 24 android:strokeColor="#CBCBCB" android:strokeLineCap="round" 25 android:strokeLineJoin="round" android:strokeWidth="4"/> 26 27 2.取色器icon_huawei_color_click_selector.xml,三個狀態的顏色(color可以替換成圖片drawable): 28 <?xml version="1.0" encoding="utf-8"?> 29 <selector xmlns:android="http://schemas.android.com/apk/res/android"> 30 //按鈕可用(響應事件),非按下狀態的顏色 31 <item android:color="@color/theme_huawei_color" android:state_enabled="true" android:state_pressed="false"/> 32 //按鈕可用(響應事件),按下時的顏色 33 <item android:color="@color/theme_huawei_color_30" android:state_enabled="true" android:state_pressed="true"/> 34 //默認狀態下的背景顏色,按鈕不可用(不響應事件) 35 <item android:color="#FF0064CC" android:state_enabled="false"/> 36 </selector> 37 38 3.屬性介紹: 39 android:state_selected選中 40 41 android:state_focused獲得焦點 42 43 android:state_pressed點擊 44 45 android:state_enabled設置是否響應事件,指所有事件 46 47 48 49 4、Drawable-Selector 50 android:drawable 放一個drawable資源 51 android:state_pressed 是否按下,如一個按鈕觸摸或者點擊。 52 android:state_focused 是否取得焦點,比如用戶選擇了一個文本框。 53 android:state_hovered 光標是否懸停,通常與focused state相同,它是4.0的新特性 54 android:state_selected 被選中,它與focus state並不完全一樣,如一個list view 被選中的時候,它里面的各個子組件可能通過方向鍵,被選中了。 55 android:state_checkable 組件是否能被check。如:RadioButton是可以被check的。 56 android:state_checked 被checked了,如:一個RadioButton可以被check了。 57 android:state_enabled 能夠接受觸摸或者點擊事件 58 android:state_activated 被激活 59 android:state_window_focused 應用程序是否在前台,當有通知欄被拉下來或者一個對話框彈出的時候應用程序就不在前台了 60 61 5、通過監聽editText變化,來控制button可點擊和可用狀態 62 mTxtTransEdit.addTextChangedListener(new TextWatcher() { 63 64 @Override 65 public void beforeTextChanged(CharSequence s, int start, int count, int after) { 66 67 } 68 69 @Override 70 public void onTextChanged(CharSequence s, int start, int before, int count) { 71 if (s.length() == 0) { 72 setTxtTransBtnStatus(false); 73 } else { 74 setTxtTransBtnStatus(true); 75 } 76 } 77 78 @Override 79 public void afterTextChanged(Editable s) { 80 setNohistoryState(); 81 } 82 }); 83 84 private void setTxtTransBtnStatus(boolean isEnable) { 85 mRlSend.setEnabled(isEnable); 86 mRlSend.setClickable(isEnable); 87 mtxtTransBtn.setEnabled(isEnable); 88 mtxtTransBtn.setClickable(isEnable); 89 } 90