我常用的Android库-AndroidX

前言

随着使用AndroidX,哪些我常用的库有些已经不能用了,所以就重新记录以下AndroidX下常用的库。

Android官方

1
2
3
4
5
6
7
8
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.multidex:multidex-instrumentation:2.0.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

我的常用组件

Kotlin

Kotlin & anko

anko

project - build.gradle

1
2
3
4
5
6
7
8
buildscript {
ext.kotlin_version = '1.1.51'
//....
dependencies {
//...
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

app - build.gradle

1
2
3
4
5
6
7
8
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.anko:anko:$anko_version"
}

UI

下拉刷新

1
2
implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.0'
implementation 'com.scwang.smartrefresh:SmartRefreshHeader:1.1.0'

UI框架

QMUI https://qmuiteam.com/android

1
implementation 'com.qmuiteam:qmui:2.0.0-alpha10'

图片圆角&背景圆角

图片圆角RoundedImageView

背景圆角FlycoRoundView

1
2
3
4
//图片圆角
implementation 'com.makeramen:roundedimageview:2.3.0'
//背景圆角
implementation 'com.flyco.roundview:FlycoRoundView_Lib:1.1.4@aar'

消息提示

Toasty

1
implementation 'com.github.GrenderG:Toasty:1.2.8'

初始化样式

1
2
3
4
5
6
7
8
9
10
11
private fun initToast() {
Toasty.Config.getInstance()
.setTextColor(ZJColor.white)
.setWarningColor(ZJColor.black_tran)
.setSuccessColor(ZJColor.black_tran)
.setInfoColor(ZJColor.black_tran)
.setErrorColor(ZJColor.black_tran)
.setTextSize(14)
.setToastTypeface(Typeface.MONOSPACE)
.apply()
}

弹出窗口

Material Dialogs

1
implementation 'com.afollestad.material-dialogs:core:0.9.6.0'

设置主题

1
2
3
4
5
6
7
8
9
MaterialDialog.Builder(this)
.title("温馨提示")
.theme(Theme.LIGHT)
.content("您确定要删除吗?")
.positiveText("确认")
.negativeText("取消")
.onPositive { dialog, which ->
}
.show()

不设置主题的话,在不同的系统下有的是亮色有的是暗色

设置自定义View

1
2
3
4
5
6
7
8
9
10
11
12
dialog = MaterialDialog.Builder(this)
.theme(Theme.LIGHT)
.title("加入群")
.customView(R.layout.s_dialog_input, true)
.positiveText("加入")
.negativeText("取消")
.onPositive { dialog, which ->

}
.show()

(dialog?.findViewById(R.id.input_edittext) as EditText).hint = "请输入要加入的群号"

Github:https://github.com/youth5201314/banner

1
implementation 'com.youth.banner:banner:2.0.11'

BGABanner-Android

1
2
//Banner
implementation 'cn.bingoogolapple:bga-banner:2.2.4@aar'

仿iOS Segment

SHSegmentControl

1
implementation 'com.7heaven.widgets:segmentcontrol:1.17'

加载HTML的TextView

html-textview

1
2
3
dependencies {
implementation 'org.sufficientlysecure:html-textview:3.5'
}

视频播放器

DKPlayer

1
2
3
4
5
6
//# 必选,内部默认使用系统mediaplayer进行解码
implementation 'com.github.dueeeke.dkplayer:dkplayer-java:3.2.6'
//# 可选,包含StandardVideoController的实现
implementation 'com.github.dueeeke.dkplayer:dkplayer-ui:3.2.6'
//# 可选,使用exoplayer进行解码
implementation 'com.github.dueeeke.dkplayer:player-exo:3.2.6'

功能

权限

https://github.com/yanzhenjie/AndPermission

1
implementation 'com.yanzhenjie:permission:2.0.3'

Adapter

BaseRecyclerViewAdapterHelper

1
implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.4'

网络请求

Retrofit+RX

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//网络请求
implementation 'io.reactivex.rxjava2:rxjava:2.1.10'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
implementation 'io.reactivex:rxandroid:1.2.1'
implementation 'com.jakewharton.rxbinding2:rxbinding:2.1.1'

implementation 'com.squareup.retrofit2:retrofit:2.6.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
implementation 'com.squareup.okhttp3:logging-interceptor:4.0.1'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'

implementation 'com.trello.rxlifecycle2:rxlifecycle:2.2.1'
implementation 'com.trello.rxlifecycle2:rxlifecycle-components:2.2.1'
implementation 'com.trello.rxlifecycle2:rxlifecycle-android:2.2.1'
//AutoDispose解决RxJava内存泄漏
implementation 'com.uber.autodispose:autodispose:0.7.0'
implementation 'com.uber.autodispose:autodispose-android:0.7.0'
implementation 'com.uber.autodispose:autodispose-android-archcomponents:0.7.0'

OkGo+FastJson

  • okhttp-OkGo

  • fastjson

    1
    2
    3
    4
    5
    //网络请求
    implementation 'com.lzy.net:okgo:3.0.4'
    implementation 'com.lzy.net:okrx2:2.0.2'
    //JSON
    implementation 'com.alibaba:fastjson:1.2.46'

数据库

android-lite-orm

1
引用Jar包

事件总线

EventBus

1
implementation 'org.greenrobot:eventbus:3.1.1'

图片加载

Glide

Glide

1
2
//Glide
implementation 'com.github.bumptech.glide:glide:4.9.0'

Gif加载

android-gif-drawable

1
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.+'

事件视图绑定

Butterknife

1
2
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

如果编程语言为Kotlin, 替换 annotationProcessorkapt

Kotlin项目不建议再使用

1
implementation "org.jetbrains.anko:anko:$anko_version"

可以使用Anko代替

应用崩溃检测服务

Bugly

1
implementation 'com.tencent.bugly:crashreport_upgrade:1.4.5'