- 1. 项目结构 (MVP)
- 2. 配置主题
- 3. 依赖库与 SDK
- 4. 配置 Gradle
- 5. 制定开发规范
- 6. 其它
-
如果项目比较小
-
如果项目比较大
1. 先在 color.xml 中写好需要的颜色
#ff5722
#673AB7
#311B92
#fff
#888888
#dddddd
#999999
注意 : color.xml 是配色表。应该是描述颜色而不是对字体颜色,背景颜色等的定义。这样能防止相近的颜色重复定义。而导致界面颜色不统一。
2. 在 style.xml 里定义主题
@color/DeepPurple
@color/DeepPurple900
@color/Orange
在 res 目录下,创建一个 values-v21 目录,再创建一个 style.xml
true
?colorPrimaryDark
然后在 AndroidManifest.xml 文件中修改 application 的 theme 属性为上面定义的 AppTheme .即可实现沉浸式状态栏。
3. 依赖库与 SDK必选的库
//Butter Knife View 注解库
implementation 'com.jakewharton:butterknife:10.2.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.0'
//TitleBar 统一标题栏
implementation 'com.github.getActivity:TitleBar:8.6'
// RecyclerAdapter 万能适配器
implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.7'
// glide 图片加载库
implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
// Material Dialog 向下兼容库
implementation 'com.afollestad.material-dialogs:core:3.3.0'
// 网络请求
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.google.code.gson:gson:2.8.9'
implementation 'io.reactivex:rxjava:1.2.1'
implementation 'io.reactivex:rxandroid:1.2.1'
implementation 'com.squareup.retrofit2:converter-gson:2.6.1'
implementation 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
SDK 融云——即时通讯 友盟——数据统计,推送,意见反馈,自动更新,第三方分享及登录,社区 七牛——云存储 Mob——短信验证 Bmob——做后台不求人
**提示:**依赖这一大堆库和 SDK 以后。建议在合适的时机初始化他们,而不是全堆在 Application 的 onCreate() 里面。这样会导致启动时间过长。启动后也会较卡。虽然是不会影响功能正常使用。
4. 配置 Gradle某些 SDK
运行时需要检查签名是否正确。所以在 debug
模式时也必须用正式 KEY
签名。而把签名放进版本控制不是明智的做法。所以推荐下面的做法:
- 在
app
的gradle
加入下面代码
Properties props = new Properties()
props.load(new FileInputStream(file("signing.properties")))
android {
signingConfigs {
release{
keyAlias props['KEY_ALIAS']
keyPassword props['KEY_PASSWORD']
storeFile file(props['KEYSTORE_FILE'])
storePassword props['KEYSTORE_PASSWORD']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
debug {
signingConfig signingConfigs.release
}
}
}
- 在
app
的gradle
文件同级目录新建signing.properties
文件,里面填入你的key
的相应信息
KEYSTORE_FILE = C:\\Users\\Mr.Jude\\Documents\\Android\\HelloWorld.jks
KEYSTORE_PASSWORD = xxxxxx
KEY_ALIAS = xxxxxx
KEY_PASSWORD = xxxxxx
- 将
signing.properties
添加进忽略目录。
其他人 pull
下来代码后。自己新建 signing.properties
填入相应信息后即可编译成功。
为了避免合作开发写的代码风格迥异。
-
所有
Activity
继承BaseActivity
-
所有
Fragment
继承BaseFragment
-
所有
Presenter
继承BasePresenter
这样利于生命周期管理。也可以方便的全局修改。 -
命名,例:
AccountFragment
UserDetailActivity
-
layout 命名,例
activity_collection
fragment_account
item_person
include_toolbar
view_progress
不过对于庞大项目的开发。近百个activity开头的layout列表还是会眼瞎。所以那种情况会在前面加上模块名。 -
id 命名,例
btn_send
tv_name
list_persons
et_password
然后用butterknife
的插件生成变量会自动将下划线变成驼峰命名 -
变量命名:以
m
开头。例mAdapter
使用时按一个m
全都出来了 -
方法命名:与其写好名字不如写好注释。
TextView 使用官方标准字体
style="@style/TextAppearance.AppCompat.Display4"
style="@style/TextAppearance.AppCompat.Display3"
style="@style/TextAppearance.AppCompat.Display2"
style="@style/TextAppearance.AppCompat.Display1"
style="@style/TextAppearance.AppCompat.Headline"
style="@style/TextAppearance.AppCompat.Title"
style="@style/TextAppearance.AppCompat.Subhead"
style="@style/TextAppearance.AppCompat.Body2"
style="@style/TextAppearance.AppCompat.Body1"
style="@style/TextAppearance.AppCompat.Caption"
style="@style/TextAppearance.AppCompat.Button"
Button 使用 Material Design 标准样式
style="@style/Widget.AppCompat.Button"
style="@style/Widget.AppCompat.Button.Borderless"
style="@style/Widget.AppCompat.Button.Borderless.Colored"
style="@style/Widget.AppCompat.Button.Small"
6. 其它
定好网络请求写法。文件存储方式与位置。写好项目所使用的类库框架用法。
好了,下面就开始正式开发吧!