android 其他的一些點
- 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 |