Android学习之文件选择器LFilePicker
来源:互联网 发布:淘宝浏览器打开就关闭 编辑:程序博客网 时间:2024/05/29 01:55
在 Android 开发中如果需要选择某个文件,可以直接调取系统的文件管理器进行选择,但是无法保证各个厂商的手机界面一致,而且解析Uri 还比较繁琐,如果还需要多选呢?需要文件类型过滤呢?老板说界面丑呢?
那么福利来了,你可以使用LFilePicker,它都支持什么呢?
还算漂亮的界面
各种手机一致的体验
多种界面风格
自定义标题文字和颜色
文件多选或者单选
文件类型过滤
Fragment启动
国际化(中英文切换)
在哪里能找到它呢?Bio Bio Bio
传送门:https://github.com/leonHua/LFilePicker
心急的人可以直接根据说明文档进行使用了,任性的人跟着我继续走~~~
先看看界面,万一丑的不行呢?
好了还算可以把,和经典的Windows风格类似,先用用看吧。怎么用呢?
基础用法
1.添加依赖
compile 'com.leon:lfilepickerlibrary:1.0'
【P.S.】 话说为了能够方便的依赖使用可是操碎了心,将项目库开源到JCenter使用的过程中趟了很多坑,如果感兴趣,可以查看文章:新版Bintray下将Android Library 开源到JCenter 的正确姿势
另外,如果网络环境有问题无法正常使用compile指令(像我这样),良心提供 aar 文件下载使用。
下载链接:lfilepickerlibrary
【P.S.】 如果不知道 aar 如何使用,请参考文章:Android中 aar 文件的日常使用
2.添加文件读写权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
3.打开选择界面
你可以在Activity中打开:
new LFilePicker() .withActivity(MainActivity.this) .withRequestCode(Consant.REQUESTCODE_FROM_ACTIVITY) .start();
也可以在Fragment中打开(同时支持v4包SupportFragment):
new LFilePicker().withSupportFragment(mFragment) .withRequestCode(Consant.REQUESTCODE_FROM_FRAGMENT) .withTitle("Open From Fragment") .start();
4.接收选择返回值
重写方法并获取数据:
@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) { if (requestCode == Consant.REQUESTCODE_FROM_ACTIVITY) { List<String> list = data.getStringArrayListExtra(Constant.RESULT_INFO); Toast.makeText(getApplicationContext(), "选中了" + list.size() + "个文件", Toast.LENGTH_SHORT).show(); } }}
已经以上你已经能够正常使用了,但是说好的那么多特性呢?接下来,深入一点
自由使用
文件夹和文件图标太low?换!
new LFilePicker() .withActivity(this) .withRequestCode(Consant.REQUESTCODE_FROM_ACTIVITY) .withIconStyle(Constant.ICON_STYLE_YELLOW) .start();
withIconStyle(mIconType)提供三种风格:
Constant.ICON_STYLE_YELLOW 经典黄(默认风格)
Constant.ICON_STYLE_GREEN 清新绿
Constant.ICON_STYLE_BLUE 柔和蓝
选择界面标题不合适?换!
new LFilePicker() .withActivity(this) .withRequestCode(Consant.REQUESTCODE_FROM_ACTIVITY) .withTitle("我的标题")//标题文字 .withTitleColor("#FF99CC")//文字颜色 .start();
想要限制单选或者多选?换!
new LFilePicker() .withActivity(this) .withRequestCode(Consant.REQUESTCODE_FROM_ACTIVITY) .withMutilyMode(true) .start();
withMutilyMode(true):true代表多选;false代表单选
想要限制选择文件类型?过滤!
new LFilePicker() .withActivity(this) .withRequestCode(Consant.REQUESTCODE_FROM_ACTIVITY) .withFileFilter(new String[]{".txt", ".png"}) .start();
英文怎么搞?已经内置实现!
将手机语言调整为英文后:
返回图标不喜欢?换!
new LFilePicker() .withActivity(this) .withRequestCode(Consant.REQUESTCODE_FROM_ACTIVITY) .withBackIcon(Constant.BACKICON_STYLEONE) .start();
withBackIcon() 提供三种风格:
Constant.BACKICON_STYLEONE
Constant.BACKICON_STYLETWO
Constant.BACKICON_STYLETHREE
标题背景颜色不喜欢?换!
new LFilePicker() .withActivity(this) .withRequestCode(Consant.REQUESTCODE_FROM_ACTIVITY) .withBackgroundColor("#FF9966") .start();
切换选择路径?已经包含,随便选!
结束
- Android学习之文件选择器LFilePicker
- LFilePicker---文件选择器
- Android学习之分段选择器的实现
- 【android学习】xml之背景选择器selector
- Swing之文件选择器
- Android文件选择器
- android 文件选择器控件
- Android文件选择器
- Android文件选择器
- Android图片文件选择器
- android文件选择器
- Android文件选择器
- Android学习笔记之样式和主题之选择器
- jQuery学习之--选择器
- css学习之选择器
- jQuery学习之选择器
- CSS学习之选择器
- Android 之 日期选择器
- pip install jupyter
- C# String.Format用法和格式说明
- 论一名项目经理的能力素养
- xml解析pull sax doc
- 欢迎使用CSDN-markdown编辑器
- Android学习之文件选择器LFilePicker
- 查询数据库记录
- 第三届省赛题 AMAZING AUCTION
- 多表连接
- 【cocos2dx】box2d使用
- Huffman Code 编码译码
- 杭电 1241 Oil Deposits
- Spring学习:bean的自动装配(注解)
- 活动选择