想必大家经常用到选择文件的时候吧,这里我介绍一个开源库
内库地址
那我就说下用法咯
一样加入依赖
compile 'com.github.angads25:filepicker:1.1.0'
public void showFile(){
DialogProperties properties = new DialogProperties();
//这个是设置单选和多选的 单选是SINGLE_MODE
properties.selection_mode = DialogConfigs.MULTI_MODE;
properties.selection_type = DialogConfigs.DIR_SELECT;
// properties.root = new File("/sdcard/");
properties.root=new File(DialogConfigs.DEFAULT_DIR);
properties.extensions = null;
FilePickerDialog dialog = new FilePickerDialog(MainActivity.this, properties);
dialog.setDialogSelectionListener(new DialogSelectionListener() {
@Override
public void onSelectedFilePaths(String[] files){
if (files.length <= 0) return;
Toast.makeText(MainActivity.this,"选中文件长度:"+files.length,Toast.LENGTH_SHORT).show();
}
});
dialog.show();
}
不好意思,我发现上面的类库有点BUG,我最近会花时间改下。。。问题不大就是选择返回的时候有点显示错误!!!我最近有空看下自己拿过来改下看看。。。。。。。