Android Studio 中live tempplates的
作者:
会灰的大飞狼 | 来源:发表于
2017-09-20 15:17 被阅读0次
1.ctrl+alt+s 打开设置,搜索live temp

image.png
2. Define选择java.填好上面几个信息就可以用了.

image.png
3. 最后我的效果图

image.png
4. 几个模版
(1) 弱引用handler
//handler
public static class MyHandler extends Handler {
public final WeakReference<$className$> mWeakReference;
public MyHandler($className$ activity) {
mWeakReference = new WeakReference<>(activity);
}
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
$className$ activity = mWeakReference.get();
if (msg.what == $code$) {
if (activity != null) {
}
}
}
}
(2)单例
//singleton
private volatile static $className$ sInstance;
public static $className$ getInstance() {
if (sInstance == null) {
synchronized ($className$.class) {
if (sInstance == null) {
sInstance = new $className$();
}
}
}
return sInstance;
}
private $className$() {
}
最后编写代码的时候输入快捷键就可以了

image.png
本文标题:Android Studio 中live tempplates的
本文链接:https://www.haomeiwen.com/subject/nqdosxtx.html
网友评论