[Android]仿IOS选择拍照相册底部弹出
16lz
2022-05-02
[Android]仿IOS选择拍照相册底部弹出框
@Author GQ 2016年07月18日 由于主要用来弹出选择拍照和选择相册功能,就限定只有两个条目。没有像网上其他demo一样做扩展。可以配合网上的ImagePicker等直接使用。
效果图
- Android仿IOS选择拍照相册底部弹出框
- 效果图
- AndroidStudio使用
- 使用
1. AndroidStudio使用
dependencies { compile 'com.guoqi.widget:actionsheet:1.0'}
2. 使用
- JAVA 代码
1.实现接口 implements ActionSheet.OnActionSheetSelected2.在某个点击事件中添加: ActionSheet.showSheet(this, this, null);3.然后重写点击方法:@Override public void onClick(int whichButton) { switch (whichButton) { case ActionSheet.CHOOSE_PICTURE: //相册 choosePic(); break; case ActionSheet.TAKE_PICTURE: //拍照 takePic(); break; case ActionSheet.CANCEL: //取消 break; } } //加入自己的逻辑public void takePic(){ String state = Environment.getExternalStorageState(); if (state.equals(Environment.MEDIA_MOUNTED)) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File outDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); if (!outDir.exists()) { outDir.mkdirs(); } File outFile = new File(outDir, System.currentTimeMillis() + ".jpg"); picPath = outFile.getAbsolutePath(); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(outFile)); intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); startActivityForResult(intent, ActionSheet.TAKE_PICTURE); } else { Toast.makeText(this, "请确认已经插入SD卡", Toast.LENGTH_SHORT).show(); }}//加入自己的逻辑public void choosePic(){ Intent openAlbumIntent = new Intent(Intent.ACTION_PICK); openAlbumIntent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*"); startActivityForResult(openAlbumIntent, ActionSheet.CHOOSE_PICTURE);}
更多相关文章
- Android中使用硬盘模拟SD卡
- 深入解析_Android的自定义布局
- 关于 Android(安卓)程序使用 Support Library 属性的几点说明
- Android开发周报:Android将使用OpenJDK、React Native详解
- Android(安卓)ADB命令的使用
- Android上使用ASIFT实现对视角变化更鲁棒的特征匹配
- 箭头函数的基础使用
- NPM 和webpack 的基础使用
- Python list sort方法的具体使用