美文网首页
AndroidStudio之live templates

AndroidStudio之live templates

作者: 李庆雪 | 来源:发表于2017-03-31 13:54 被阅读0次

[TOC]

今天的内容可以叫程序员偷懒,在eclipse中有自动补全,那在Androidstudio中呢?当然强大的AS肯定不会叫开发者失望的,反而更加灵活的实现了自定义模块Live Template.接下来开始Live Template的操作吧!

Live Template通过翻译得知叫做实时模板,在 AS 中有两种模板,一种就是你在新建一个 Activity 的时候可以选择 Empty Activity、FullScreen Activity 之类的,这个一般是对你整个文件而言的,还有一种就是本篇要介绍的 Live Template ,这个会在一些常用的代码片段中有重要作用。

查看Live Templates

打开 Setting -> Editor -> Live Templates ,可以看到默认已经有很多 Live Templates 了,可以看下我的截图 Android 分类下有如下这些模板:


Live Templates 中Android模块

这个是Android默认的模块,其中熟悉的findViewById就可以用fbc代替,很是简单,下面是动态操作.

  • findViewById的动图

自定义单例模块

  • 先新建一个模块组
模块组
  • 创建模块


    创建模块
private static $CLASS$ instance = null;
private $CLASS$(){
}
public static $CLASS$ getInstance() {
    synchronized ($CLASS$.class) {
        if (instance == null) {
            instance = new $CLASS$();
        }
    }
    return instance;
}
  • 选择应用到Java中


设置Class的值为类名

设置显示类名 至于其他的Expression怎么设置可以参考https://www.jetbrains.com/help/idea/2017.1/live-template-variables.html
  • 代码测试
单例.gif

自定义注释模板

  • 更改author的值和date的值


结束

当然除了这些模板自己还可以定义不同需求的模板

相关文章

网友评论

      本文标题:AndroidStudio之live templates

      本文链接:https://www.haomeiwen.com/subject/mknmottx.html