圖檔名稱File Name
為了提高代碼的可讀性,圖檔名稱命名是非常重要,Android圖檔命名只能為[a-z,0-9,_],其餘的不適當的命名規則會使AndroidStudio無法Build,好的命名規則可以幫助自己快速找到需要的圖檔資源。
圖檔名稱命名規則:
Resource 中文件的命名資源文件應該以小寫 + 下劃線( _ )的格式命名。
以下是對於圖片文件的命名規則
| Asset Type | Prefix | Example |
|---|---|---|
| Action bar | ab_ |
ab_stacked.9.png |
| Button | btn_ |
btn_send_pressed.9.png |
| Dialog | dialog_ |
dialog_top.9.png |
| Divider | divider_ |
divider_horizontal.9.png |
| Icon | ic_ |
ic_star.png |
| Menu | menu_ |
menu_submenu_bg.9.png |
| Notification | notifi_ |
notifi_bg.9.png |
| Tabs | tab_ |
tab_pressed.9.png |
對於圖標的命名習慣
| Asset Type | Prefix | Example |
|---|---|---|
| Icons | ic_ |
ic_star.png |
| Launcher icons | ic_launcher |
ic_launcher_calendar.png |
| Menu icons and Action Bar icons | ic_menu |
ic_menu_archive.png |
| Status bar icons | ic_stat_notify |
ic_stat_notify_msg.png |
| Tab icons | ic_tab |
ic_tab_recent.png |
| Dialog icons | ic_dialog |
ic_dialog_info.png |
對於選擇器狀態的命名習慣
| State | Suffix | Example |
|---|---|---|
| Normal | _normal |
btn_order_normal.9.png |
| Pressed | _pressed |
btn_order_pressed.9.png |
| Focused | _focused |
btn_order_focused.9.png |
| Disabled | _disabled |
btn_order_disabled.9.png |
| Selected | _selected |
btn_order_selected.9.png |