直接上代码:
//调用kotlin对象
Function2 unitFunction2 = (params,view)->{
ImmersionBar immersionBar = ImmersionBar.with(params);
immersionBar.statusBarDarkFont(true);
if(view !=null) {
immersionBar.titleBar(view);
}
immersionBar.init();
return Unit.INSTANCE;
};
Matisse.Companion.from(MainActivity.this)
.choose(MimeTypeManager.Companion.ofImage(),true)//类型:图片/单一选择
.maxSelectable(1)//选择数量
.isCrop(true)//开启裁剪
.isCircleCrop(false)//方形裁剪
.imageEngine(new MyGlideEngine())
.theme(R.style.Matisse_Default)//样式
.setStatusBarFuture(unitFunction2)//外部设置状态栏,注意:这一步必须加,否则裁剪界面无法显示
.forResult(REQUEST_CODE_CHOOSE_MEDIA_LOCAL);//onActivityResult requestcode
由于用到了kotlin方法,需要配置kotlin
1、app build.gradle添加:
apply plugin:'kotlin-android'
apply plugin:'kotlin-android-extensions'
2、Project build.gradle添加
buildscript{
ext.kotlin_version="1.3.30"
repositories{
google()
jcenter()
mavenCentral()
}
dependencies{
classpath'com.android.tools.build:gradle:3.5.1'
classpath'org.greenrobot:greendao-gradle-plugin:3.2.2'
classpath"org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
3、用到了ImmersionBar引入:
//沉浸式状态栏
implementation'com.gyf.barlibrary:barlibrary:2.3.0'
4、MatisseKotlin的集成可以看下面参考,这里不过多赘述。
参考:
https://www.jianshu.com/p/ca1e7460fa69
https://github.com/NFLeo/Matisse-Kotlin
网友评论