介绍:
非常不错的图片选择器,功能完善,动画超赞
运行效果:
使用说明:
在root build.gradle 文件中添加以下代码:
1. allprojects {
2. repositories {
3. ...
4. maven { url "https://jitpack.io" }
5. }
6. }
然后,在app的build.gradle中添加库:
1. dependencies{
2. compile 'com.github.andremion:louvre:1.2.0'
3. }
为GalleryActivity选择一个Louvre 主题
1. <style name="AppTheme.Louvre.Light.DarkActionBar" parent="Louvre.Theme.Light.DarkActionBar">
2. <item name="colorPrimary">@color/colorPrimary</item>
3. <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
4. <item name="colorAccent">@color/colorAccent</item>
5. </style>
6.
7. <style name="AppTheme.Louvre.Dark" parent="Louvre.Theme.Dark">
8. <item name="colorPrimary">@color/colorPrimary</item>
9. <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
10. <item name="colorAccent">@color/colorAccent</item>
11. </style>
12.
13. <style name="AppTheme.Louvre.Light" parent="Louvre.Theme.Light">
14. <item name="colorPrimary">@color/colorPrimary</item>
15. <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
16. <item name="colorAccent">@color/colorAccent</item>
17. </style>
对于PreviewActivity你只需定义 accent color。
1. <style name="AppTheme.Louvre.Preview" parent="Louvre.Theme.Preview">
2. <item name="colorAccent">@color/colorAccent</item>
3. </style>
在AndroidManifest.xml中使用新主题定义Louvre Activity
1. <activity
2. android:name="com.andremion.louvre.home.GalleryActivity"
3. android:theme="@style/AppTheme.Louvre.Light.DarkActionBar" />
4. <activity
5. android:name="com.andremion.louvre.preview.PreviewActivity"
6. android:theme="@style/AppTheme.Louvre.Preview" />
在AndroidManifest.xml中添加READ_EXTERNAL_STORAGE 权限
1. <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
在你的Activity中,用下面的代码打开Louvre
1. Louvre.init(myActivity)
2. .setRequestCode(LOUVRE_REQUEST_CODE)
3. .open();
你也可以用Fragment打开Louvre,这种情况下,Fragment将得到onActivityResult callback。
1. Louvre.init(myFragment)
2. .setRequestCode(LOUVRE_REQUEST_CODE)
3. .open();
自定义picker:
设置允许选择的最大图片个数:
1. louvre.setMaxSelection(10)
设置当前选中的item
1. List<Uri> selection;
2. ...
3. louvre.setSelection(selection)
设置媒体类型,可以是这三个的任意组合:Louvre.IMAGE_TYPE_BMP, Louvre.IMAGE_TYPE_JPEG, Louvre.IMAGE_TYPE_PNG
1. louvre.setMediaTypeFilter(Louvre.IMAGE_TYPE_JPEG, Louvre.IMAGE_TYPE_PNG)
See more at the sample