android studio自动代码

    使用快捷键Ctrl+J可以看到一些几个键就可以快速生成代码的。我们可以熟悉一下我们常用的键,方便我们快速生成代码。

例如,在输入logd,按tab键,即会自动生成打印log的代码,很方便。


Log.d(TAG, "onCreate: ");

以下列举使用快捷键Ctrl+J中的所有快捷键,觉得有用的可以记下使用(区分大小写)。

--------------------------------fbc--------------------------------------

描述:findViewById with cast

() findViewById(R.id.);

 

-------------------------------打印Log---------------------------------------

logd:  Log.d(TAG, "onCreate: ");
logm:  Log.d(TAG, "onCreate() called with: savedInstanceState = [" + savedInstanceState + "]");
loge:  Log.e(TAG, "onCreate: ", );
logi:  Log.i(TAG, "onCreate: ");
logr:  Log.d(TAG, "onCreate() returned: " + );
logw:  Log.w(TAG, "onCreate: ", );
wtf:   Log.wtf(TAG, "onCreate: ", );
 

 -----------------------------System.out-----------------------------------------

serr:  System.err.println("");
souf:  System.out.printf("");
sout:  System.out.println();
soutm:  System.out.println("MainActivity.onCreate");
soutp:  System.out.println("savedInstanceState = [" + savedInstanceState + "]");
soutv:  System.out.println("text = " + text);
 

-----------------------------快速设置visibility-----------------------------------------

visible:  .setVisibility(View.VISIBLE);
gone:  .setVisibility(View.GONE);

 

----------------------------if判断------------------------------------------

ifn:
if (text == null) {

}
inn:
if (text != null) {

}
inst:
if (text instanceof Object) {
    Object o = (Object) text;

}
lazy:
if (text == null) {
    text = new TextView();
}

 

--------------------------循环(只介绍3种常用的)--------------------------------------------

foreach:
for ( : ) {
    
}
fori:
for (int i = 0; i < ; i++) {
    
}
itli:
for (int i = 0; i < list.size(); i++) {
    Object o =  list.get(i);

}

 -----------------------------Toast-----------------------------------------

Toast:  
Toast.makeText(this, "", Toast.LENGTH_SHORT).show();

 

-----------------------------比较大小和字符-----------------------------------------

mn:  = Math.min(, );
mx:  = Math.max(, );

rgS:  .getString(R.string.);
Sfmt:  String.format("", );

 

-------------------------运行主线程和一些包围---------------------------------------------

rouiT:  
getActivity().runOnUiThread(new Runnable() {
    @Override
    public void run() {

    }
});
WL:  
.readLock().lock();
try {

} finally {
    .readLock().unlock();
}
RL:
.writeLock().lock();
try {

} finally {
    .writeLock().unlock();
}
thr:  throw new;

toar:  .toArray(new Object[.size()])

UnparcelIntArray:
int intArray[] = in.createIntArray();
UnparcelStringArray:
String stringArray[] = in.createStringArray();

 

---------------------------其他-------------------------------------------

todo// TODO: 2018/4/22
fixme:  // FIXME: 2018/4/22
stopship:  // STOPSHIP: 2018/4/22

                
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值