美文网首页
Android项目准备篇

Android项目准备篇

作者: liwei_happyman | 来源:发表于2017-06-19 15:33 被阅读25次

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

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

然后点击ok。

5.然后在android studio中新建一个类Test,可以看到自动添加了注释,在描述中加入该类的具体功能。

二、全局获取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'
}

相关文章

网友评论

      本文标题:Android项目准备篇

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