文章目录
  1. 1. Android 开发
  2. 2. Android 注释
  3. 3. Android Log
  4. 4. Android Parcelable
  5. 5. Android XML

工欲善其事 必先利其器

Writing More Code by Writing Less Code with Android Studio Live Templates.

对于 Android 开发中常用的小的代码块,每次都写一遍既浪费时间而且多了容易出错。不用着急,这些问题老前辈们肯定也早已经遇到,IDE 给我提供 Live template 来提高我们的开发效率。

实现效果如图:
Live Template

Android Studio 为我们提供了5类 Live template,分别是:

  1. Android 开发
  2. Android 注释
  3. Android Log
  4. Android Parcelable
  5. Android XML

Live template 的位置:File > Settings > Editor > Live Templates

Android 开发

前缀含义
constDefine android style int constant
fbcfindViewById with cast
foreachCreate a for each loop
goneSet view visibility to GONE
IntentViewCreates an Intent with ACTION_VIEW
keyKey for a bundle
newInstancecreate a new Fragment instance with arguments
noInstanceprivate empty constructor to prohibit instance creation
rgSget a String from resources
rouiTrunOnUIThread
sbcblock comment for structuring code
SfmtString format
starterCreates a static start(…) helper method to start an Activity
ToastCreate a new Toast
ViewConstructorsAdds generic view constructors
visibleSet view visibility to VISIBLE
wrapItadds a gradle wrapper task

Android 注释

前缀含义
ccodecode tag for javadoc
cfalseputs false in a comment section
clinklink from within javadoc
ctrueputs true in a comment section
fixmeadds // FIXME
noopindicate that a method does not have any operations
stopshipadds // STOPSHIP
todoadds // TODO

Android Log

前缀含义
logdLog.d(TAG, String)
logeLog.e(TAG, String, Exception)
logiLog.i(TAG, String)
logmLog method name and its arguments
logrLog result of this method
logtA static logtag with your current classname
logwLog.w(TAG, String, Exception)
wtfLog.wtf(TAG, String, Exception)

Android Parcelable

前缀含义
ParcelableCreate a parcelable block for your current class
ParcelableEnumCreate a parcelable block for your current enum
ParcelableEnumTestCreates basic parcelable enum test methods
ParcelBooleanwrites a single boolean value to a parcel
UnparcelBooleanreads a single boolean value from a parcel
UnparcelIntArrayUnparcels an int array
UnparcelStringArrayUnparcels a String array

Android XML

前缀含义
appNsadds application namespace
lhandroid:layout_height=""
lhmandroid:layout_height="match_parent"
lhwandroid:layout_height="wrap_content"
lwandroid:layout_width=""
lwmandroid:layout_width="match_parent"
lwwandroid:layout_width="wrap_content"
toolsNsadds tools namespace to Android xml file


本文地址 http://ihongqiqu.com/2016/03/24/Android-Studio-Live-Template/ 作者为 Zhenguo

author:Zhenguo
Author: Zhenguo      Blog: http://ihongqiqu.com/     Email: jinzhenguo1990@gmail.com
I have almost 6 years of Android application development experience and have a keen interested in the latest emerging technologies. I use my spare time to turn my experience, ideas and love for Android tech into informative articles, tutorials and more in hope to help others and learn more.
文章目录
  1. 1. Android 开发
  2. 2. Android 注释
  3. 3. Android Log
  4. 4. Android Parcelable
  5. 5. Android XML
返回顶部