Android项目准备篇

一、每个功能页面的描述、作者与邮箱等基本设置

1.点击菜单栏的“File“->“Settings”,打开Settings窗口。
Android项目准备篇_第1张图片
2.点击“IDE Settings”下面的“File and Code Templates”,然后选中Templates里面的Class。
Android项目准备篇_第2张图片
3.然后选中Includes tab下面的File Header。
Android项目准备篇_第3张图片
4.在最右边的输入框中就可以输入我们想要设置的注释模板了。比如我们输入:
/**
 * 描述:
 * 作者:Wayne on ${DATE} ${HOUR}:${MINUTE}
 * 邮箱:[email protected]
 */

然后点击ok。

Android项目准备篇_第4张图片
5.然后在android studio中新建一个类Test,可以看到自动添加了注释,在描述中加入该类的具体功能。
Android项目准备篇_第5张图片

二、全局获取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文件的标签下进行指定就可以了,代码如下


    
    

这样就实现了一种全局获取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'
}

你可能感兴趣的:(Android项目准备篇)