android 开发规范 (6) - 其他及附录

android 其他的一些点

  1. Activity 和 Fragment 传参

Activitie 和 Fragment 的传参必须要有规范的书写方式,常用的方式如下:

  • Activity:
    studio 内置了 starter 关键字,我们只需要在一个 activity 类中输入 starter 这个关键字,系统就会默认帮我们生成一个 Activity 启动的静态方法:
public static void start(Context context, User user) {
      Intent starter = new Intent(context, MainActivity.class);
      starter.putParcelableExtra(EXTRA_USER, user);
      context.startActivity(starter);
}
  • Fragment :
    同理,我们在 Fragment 中输入 newInstance 这个关键字,也会生成默认的静态方法:
public static MainFragment newInstance(User user) {
      Bundle args = new Bundle();
      args.putParcelable(ARGUMENT_USER, user);
      MainFragment fragment = new MainFragment();
      fragment.setArguments(args);
      return fragment;
}

附录

UI 控件缩写表

名称 缩写
Button btn
CheckBox cb
EditText et
FrameLayout fl
GridView gv
ImageButton Ib
ImageView iv
LinearLayout ll
ListView lv
ProgressBar pb
RadioButtion rb
RecyclerView rv
RelativeLayout rl
ScrollView sv
SeekBar sb
Spinner spn
TextView tv
ToggleButton tb
VideoView vv
WebView wv

常见的英文单词缩写表

名称 缩写
average avg
background bg (主要用于布局和子布局的背景)
buffer buf
control ctrl
current cur
default def
delete del
document doc
error err
escape esc
icon ic(主要用在 App 的图标)
increment inc
information info
initial init
image img
Internationalization 18N
length len
library lib
message msg
password pwd
position pos
previous pre
selector sel(主要用于某一 view 多种状态,不仅包括 ListView 中的 selector,还包括按钮的 selector)
server srv
string str
temporary tmp
window win

你可能感兴趣的:(android 开发规范 (6) - 其他及附录)