Android代码规范

代码:

1.Activity 命名一律使用 模块名+Activity 的方式。例如,LoginActivity、SignupActivity。

2.Fragment 命名一律使用 模块名+Fragment 的方式。

3.自定义View:Custom(建议)+功能名+View/ViewGroup(具体的组件名称)。例如:CustomImageScroller、CustomRatingBar。

4.Widget 小组件:ScanWidget、WeatherWidget。

5.Dialog对话框:功能名+Dialog。例如:LoginDialog、ProgressDialog。

6.尽量在每一个Activity或类中加入TAG,方便我们查看Activity的信息。(Tip : 使用Android Studio提供的快捷键logt可快速生成当前 类的常量)

资源:

1.控件Id命名:控件缩写 _模块(module) _功能名(function)

控件类型 ID命名规则
TextView tv_module_function
EditText et_module_function
ImageView iv_module_function
Button btn_module_function
ListView lv_module_function
GridView gv_module_function
CheckBox check_module_function
RadioButton radio_module_function
LinearLayout ll_module_function
RelativeLayout rl_module_function
FrameLayout fl_module_function
GridLayout gl_module_function
······ ······

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

2.Color资源命名:

Resources Type 命名规则
color

组件名+具体作用名。例 R.color.button_text

 

 

 

 

 

3.String资源命名:

Resources Type 命名规则
string

具体功能。 例 R.string.hello

 

 

 

 

4.Drawable资源命名:

Resources Type 命名规则
launcher icon ic_launcher。例R.drawable.ic_launcher
normal icon ic_具体模块_功能。例R.drawable.ic_audio_pause
Toolbar icon ic_ab_功能名。例如ic_ab_search
selector selector_模块_功能名。例如 selector_login_button
shape shape_模块功能名状态。例如 R.drawable.shape_login_button_normal

 

 

 

 

 

 

 

 

 

 

 

5.Layout资源命名:

类型 命名规则
activity activity_模块名。例如 R.layout.activity_login
fragment fragment_模块名。例如 R.layout.fragment_login_layout_header
include layout_模块名_功能名。例如 @layout/layout_login_bottom
adapter adapter_item_模块名_功能名。例如 R.layout.adapter_item_simple_text
dialog dialog_模块_功能名。例如 R.layout.dialog_time_picker
list header header_模块_功能。例如 R.layout.header_main_top_ad
list footer footer_模块_功能。例如 R.layout.footer_main_bottom_action
widget widget_模块_功能。例如 R.layout.widget_app_clock
······ ······

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

6.Menu资源命名:

Resources Type 命名规则
menu

menu_模块名。例如 menu_login

 

 

 

 

 

7.Values资源命名:

Resources Type 命名规则
color 模块名_color。例如 material_design_color
dimens 模块名_dimens。例如 material_design_dimens
style 模块名_style。例如 material_design_style
themes 模块名_themes。例如 material_design_themes
posted @ 2018-11-13 16:00  软件1604-27-苏文江  阅读(142)  评论(0编辑  收藏  举报