当前位置: 移动技术网 > IT编程>移动开发>Android > Android 实现IOS选择拍照相册底部弹出的实例

Android 实现IOS选择拍照相册底部弹出的实例

2019年07月24日  | 移动技术网IT编程  | 我要评论

pizi,jxeea,海南省儋州市政府网

android 实现ios选择拍照相册底部弹出的实例

效果图

1. androidstudio使用

dependencies {

  compile 'com.guoqi.widget:actionsheet:1.0'

}

2. 使用

//1.实现接口

 implements actionsheet.onactionsheetselected


//2.在某个点击事件中添加:
 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);
}



感谢阅读,希望能帮助到大家,谢谢大家对本站的支持,如有疑问请留言或者到本站社区交流讨论,大家共同进步!

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网