一、每个功能页面的描述、作者与邮箱等基本设置
1.点击菜单栏的“File“->“Settings”,打开Settings窗口。
![](https://img.haomeiwen.com/i634913/143ca1fd3eacf6e8.png)
2.点击“IDE Settings”下面的“File and Code Templates”,然后选中Templates里面的Class。
![](https://img.haomeiwen.com/i634913/fd14280ba06b03d3.png)
3.然后选中Includes tab下面的File Header。
![](https://img.haomeiwen.com/i634913/cba3b3bc347b03cf.png)
4.在最右边的输入框中就可以输入我们想要设置的注释模板了。比如我们输入:
/**
* 描述:
* 作者:Wayne on ${DATE} ${HOUR}:${MINUTE}
* 邮箱:liwei_happyman@qq.com
*/
然后点击ok。
![](https://img.haomeiwen.com/i634913/0c807c4994abb28b.png)
5.然后在android studio中新建一个类Test,可以看到自动添加了注释,在描述中加入该类的具体功能。
![](https://img.haomeiwen.com/i634913/1b7f8121fd2c1370.png)
二、全局获取Context
首先创建一个MyApplication类继承自Application,代码如下所示:
public class MyApplication extends Application {
public static Context applicationContext;
@Override
public void onCreate() {
super.onCreate();
applicationContext = getApplicationContext();
}
public static Context getContext() {
return applicationContext;
}
}
接下来告知系统,当程序启动的时候应该初始化MyApplication类,而不是默认的Application类。需要在AndroidManifest.xml文件的<application>标签下进行指定就可以了,代码如下
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
…>
<application
android:name=".MyApplication"
…>
</application>
</manifest>
这样就实现了一种全局获取Context的机制。
三、导入第三方库
dependencies {
compile 'com.jakewharton:butterknife:8.6.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.squareup.retrofit2:converter-gson:2.3.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.8.1'
compile 'com.squareup.okhttp3:okhttp:3.8.1'
compile 'com.squareup.retrofit2:adapter-rxjava:2.3.0'
compile 'io.reactivex:rxandroid:1.1.0'
}
网友评论