android studio界面设计模板_android studio官网

android studio界面设计模板_android studio官网android studio模版功能简介

大家好,又见面了,我是你们的朋友全栈君。

序言

在使用android studio编写代码的时候,有一些模版功能能够增加开发效率,例如,当你输入logd 的时候,会出现如下图选项:

然后选择这一项按下enter键,就会自动出现如下代码:

Log.d(TAG, "onCreate: ");
复制代码

并且光标定位在冒号后面,这样就能方便的增加日志信息,下面来介绍一下该功能。

添加自己的模版

刚才的日志输出后的TAG没有定义,现在来创建一个TAG的模版。

进入android studio的设置界面后,然后打开如下地方:

然后点击面板右上方的家好店,就可以分别创建模版及模版组(模版指logd,模版组指AndroidLog),先选择user组,然后选择创建模版,在Abbreviation处填写输入唤起模版的关键词,对应于日志模版的 logd ,我们在这儿输入 tag ,Description处填写这一个模版的描述信息,在这儿填写 public static final String TAG = ""; ,然后在下面的内容区域填写之后模版要生成的内容,填写上 public static final String TAG = "$className$"; ,这时面板如下:

其中className变颜色了,这时模版的语法,使用两个$来标记这是带填充的内容,然后点击右侧的 Edit variables 按钮,为带填充的内容选择内容:

每一项都很好理解,我们在表达式处选择 className() ,然后点击下方的 Define 来设置这个模版能使用的地方。

我们选择java下面的 declaration,这样他能在java的class下面和字段同级的地方使用。

然后我们在class声明属性的地方输入tag:

按下enter就直接出现了如下代码:

public static final String TAG = "MainActivity";
复制代码

如此我们就成功添加了一个使用的自定义模版。

模版功能的更多介绍

在模版里输入双美元符号包裹的属性事,如果属性名输入相同的,最后能生成相同的值。如果不为属性选择函数,就需要自己去输入值,其的用法可以参见下一节的 快速生成retrofit的field注解

下面列举一些常用的属性的生成函数:

函数名 函数值
user() 当前计算机的用户名
date() 当前时间
methodName() 当前方法名
methodParameters() 当前方法的输入参数
methodReturnType() 当前方法的返回值类型
className() 当前类的类名
classNameComplete() 当前类的完整类名

还有一些其他的可以自行探索。

一些实用模版

下面介绍几个实用的模版。

页面的根布局

在xml文件里快速生成以LinearLayout为根布局的模版:

使用 DataBinding 的版本

供于测试的时候快速生成main方法的模版

Activity头部的注释

快速生成retrofit的field注解

可以将如下配置文件复制,保存为user.xml,放在android studio的配置目录里面直接引入这些模版,其中mac保存在 user/{用户名}/资源库/Preferences/AndroidStudio3.2/templates 下面,Windows保存在C盘下 .AndroidStudio3.2 的相应位置。

<templateSet group="user">
<template name="noteActivity" value="/**&#10; * Activity描述信息:&#10; * &lt;p&gt;&#10; * 需要的intent参数:&#10; * &#10; * @author $USER$&#10; * @date $DATE$&#10; */&#10;" description="Activity头部注释" toReformat="false" toShortenFQNames="true">
<variable name="USER" expression="user()" defaultValue="" alwaysStopAt="true" />
<variable name="DATE" expression="date()" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_DECLARATION" value="true" />
</context>
</template>
<template name="api" value="/**&#10; * 描述:&#10; * @param $param$&#10; * @return $return$&#10; * @exception $exception$&#10; * @see IOException&#10; */" description="api注释" toReformat="false" toShortenFQNames="true">
<variable name="param" expression="methodParameters()" defaultValue="" alwaysStopAt="true" />
<variable name="return" expression="methodReturnType()" defaultValue="" alwaysStopAt="true" />
<variable name="exception" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_DECLARATION" value="true" />
</context>
</template>
<template name="fbc" value="($cast$) findViewById(R.id.$resId$);" description="findViewById with cast" toReformat="false" toShortenFQNames="true" deactivated="true">
<variable name="cast" expression="" defaultValue="" alwaysStopAt="true" />
<variable name="resId" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_EXPRESSION" value="true" />
</context>
</template>
<template name="retrofitQuery" value="@Query(&quot;$name$&quot;) String $name$" description="retrofit Query参数" toReformat="false" toShortenFQNames="true">
<variable name="name" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_DECLARATION" value="true" />
</context>
</template>
<template name="retrofitField" value="@Query(&quot;$name$&quot;) String $name$" description="retrofit Field参数" toReformat="false" toShortenFQNames="true">
<variable name="name" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_DECLARATION" value="true" />
</context>
</template>
<template name="syso" value="System.out.println($message$);" description="System.out.println();" toReformat="false" toShortenFQNames="true">
<variable name="message" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_STATEMENT" value="true" />
</context>
</template>
<template name="tag" value="public static final String TAG = &quot;$className$&quot;;" description="public static final String TAG = &quot;&quot;;" toReformat="false" toShortenFQNames="true">
<variable name="className" expression="className()" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_DECLARATION" value="true" />
</context>
</template>
<template name="noteContentProvider" value="/**&#10; * ContentProvider描述信息:&#10; * &lt;p&gt;&#10; * &#10; * @author $USER$&#10; * @date $DATE$&#10; */&#10;" description="ContentProvider头部注释" toReformat="false" toShortenFQNames="true">
<variable name="USER" expression="user()" defaultValue="" alwaysStopAt="true" />
<variable name="DATE" expression="date()" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_DECLARATION" value="true" />
</context>
</template>
<template name="noteService" value="/**&#10; * Service描述信息:&#10; * &lt;p&gt;&#10; * &#10; * &#10; * @author $USER$&#10; * @date $DATE$&#10; */&#10;" description="Service头部注释" toReformat="false" toShortenFQNames="true">
<variable name="USER" expression="user()" defaultValue="" alwaysStopAt="true" />
<variable name="DATE" expression="date()" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_DECLARATION" value="true" />
</context>
</template>
<template name="noteBroadcastReceiver" value="/**&#10; * BroadcastReceiver描述信息:&#10; * &lt;p&gt;&#10; * 监听的广播:&#10; * &#10; * @author $USER$&#10; * @date $DATE$&#10; */&#10;" description="BroadcastReceiver头部注释" toReformat="false" toShortenFQNames="true">
<variable name="USER" expression="user()" defaultValue="" alwaysStopAt="true" />
<variable name="DATE" expression="date()" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_DECLARATION" value="true" />
</context>
</template>
<template name="noteCommon" value="/**&#10; * 类描述信息:&#10; * &#10; * @author $USER$&#10; * @date $DATE$&#10; */&#10;" description="java类头部注释" toReformat="false" toShortenFQNames="true">
<variable name="USER" expression="user()" defaultValue="" alwaysStopAt="true" />
<variable name="DATE" expression="date()" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_DECLARATION" value="true" />
</context>
</template>
<template name="layoutRoot DataBinding" value="&lt;layout&gt;&#10;&#10; &lt;data&gt;&#10; &#10; &lt;/data&gt;&#10;&#10; &lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&#10; xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;&#10; xmlns:tools=&quot;http://schemas.android.com/tools&quot;&#10; android:layout_width=&quot;match_parent&quot;&#10; android:layout_height=&quot;match_parent&quot;&#10; android:orientation=&quot;vertical&quot;&gt;&#10;&#10; &lt;/LinearLayout&gt;&#10;&lt;/layout&gt;" description="页面的初始布局 DataBinding" toReformat="false" toShortenFQNames="true">
<context>
<option name="XML" value="true" />
</context>
</template>
<template name="layoutRoot" value="&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&#10; xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;&#10; xmlns:tools=&quot;http://schemas.android.com/tools&quot;&#10; android:layout_width=&quot;match_parent&quot;&#10; android:layout_height=&quot;match_parent&quot;&#10; android:orientation=&quot;vertical&quot;&gt;&#10;&#10;&lt;/LinearLayout&gt;&#10;" description="页面的初始布局" toReformat="false" toShortenFQNames="true">
<context>
<option name="XML" value="true" />
</context>
</template>
<template name="main" value=" public static void main(String[] args) {&#10;&#10; }" description="main方法" toReformat="false" toShortenFQNames="true">
<context>
<option name="JAVA_DECLARATION" value="true" />
</context>
</template>
<template name="mode" value="&lt;input type=&quot;button&quot; name=&quot;$method$&quot; value=&quot;$method$&quot; onClick=&quot;$method$();&quot; /&gt;&#10;&#10;function $method$() {&#10;&#10; $(&quot;result&quot;).innerText = &quot;$method$&quot;;&#10; var ret = HardwareInfo.$method$();&#10; $(&quot;result&quot;).innerText = &quot;$method$成功&quot; + ret;&#10;}&#10;" description="模板" toReformat="false" toShortenFQNames="true">
<variable name="method" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_CODE" value="true" />
</context>
</template>
</templateSet>
复制代码

转载于:https://juejin.im/post/5c7caabd51882540ca1ccfbe

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/106956.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • 嵌入式–接口(一)Camera接口:DVP、MIPI[通俗易懂]

    嵌入式–接口(一)Camera接口:DVP、MIPI[通俗易懂]目录DVP接口LVDS接口MIPI接口CSI接口DVP接口sensor接口之DVP DVP(DigitalVideoPort)是传统的sensor输出接口,采用并行输出方式,d数据位宽有8bit、10bit、12bit、16bit,是CMOS电平信号(重点是非差分信号),PCLK最大速率为96MHz,接口如下图:PCLK:pixelclock,像素时钟,每个时钟对应一个像素数据;HSYNC:horizonalsynchronization,行同步信号VSYNC:vertical

  • Java语言实现自动关机程序

    Java语言实现自动关机程序@Java实现自动关机系统Java语言实现自动关机程序该项目实现了以下任务:1、提示用户,欢迎使用某某关机程序2、提示用户,输入倒计时关机的秒数3、根据用户输入的秒数,进行自动关机4、开始自动关机时,提示用户xxx秒后关机项目具体代码我们对Markdown编辑器进行了一些功能拓展与语法支持,除了标准的Markdown编辑器功能,我们增加了如下几点新功能,帮助你用它写博客:全新的界面设计,将会带来全新的写作体验;在创作中心设置你喜爱的代码高亮样式,Markdown将代码片显示选择的

  • Java实现pdf和Excel的生成及数据动态插入、导出

    点击上方“全栈程序员社区”,星标公众号 重磅干货,第一时间送达 作者:慢时光 cnblogs.com/Tom-shushu/p/14279357.html 一、序言 Excel、P…

  • 计算机网络实验四访问控制列表NAT应用

    计算机网络实验四访问控制列表NAT应用计算机网络实验四访问控制列表NAT应用

  • git如何查看分支是哪个分支创建的_git checkout -b 分支名

    git如何查看分支是哪个分支创建的_git checkout -b 分支名如何查看分支gitbranch-vvgit如何切换分支gitcheckoutbranch_name查看远程分支gitbranch-a查看本地分支gitbranch创建分支gitbranchtest切换分支到testgitcheckouttest删除本地分支gitbranch-dxxxxx查看本地和远程分支-a前面带*号的代表你当前工作目录所处的分支gitbranch-a…

  • mish函数_实现多态的方式不包括

    mish函数_实现多态的方式不包括classMish(nn.Module):@staticmethoddefforward(x):returnx*F.softplus(x).tanh()classMemoryEff

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号