使用快捷键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