运行效果:

                            

一 资源准备:

1.弹出的按钮:

(1)图库按钮(drawable中)-上角有弧度

正常状态:gallery_normal.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle" ><gradientandroid:angle="90"android:endColor="#EBEBEB"android:startColor="#EBEBEB" /><cornersandroid:bottomLeftRadius="0dp"android:bottomRightRadius="0dp"android:topLeftRadius="5dp"android:topRightRadius="5dp" /></shape>

按下状态:gallery_pressed.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle" ><gradientandroid:angle="90"android:endColor="#CACACB"android:startColor="#CACACB" /><cornersandroid:bottomLeftRadius="0dp"android:bottomRightRadius="0dp"android:topLeftRadius="5dp"android:topRightRadius="5dp" /></shape>

状态选择器:selector_gallery.xml

<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"><item android:drawable="@drawable/gallery_pressed" android:state_focused="true"/><item android:drawable="@drawable/gallery_pressed" android:state_focused="false" android:state_pressed="true"/><item android:drawable="@drawable/gallery_normal" android:state_focused="false"/></selector>

(2)拍照按钮(drawable中)-下角有弧度

正常状态:camera_normal.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle"><gradientandroid:angle="90"android:endColor="#EBEBEB"android:startColor="#EBEBEB"/><cornersandroid:bottomLeftRadius="5dp"android:bottomRightRadius="5dp"android:topLeftRadius="0dp"android:topRightRadius="0dp"/>
</shape>

按下状态:camera_pressed.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle" ><gradientandroid:angle="90"android:endColor="#CACACB"android:startColor="#CACACB" /><cornersandroid:bottomLeftRadius="5dp"android:bottomRightRadius="5dp"android:topLeftRadius="0dp"android:topRightRadius="0dp" />
</shape>

状态选择器:selector_camera.xml

<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"><item android:drawable="@drawable/camera_pressed" android:state_focused="true"/><item android:drawable="@drawable/camera_pressed" android:state_focused="false" android:state_pressed="true"/><item android:drawable="@drawable/camera_normal" android:state_focused="false"/></selector>

(3)取消按钮(drawable中)-四角有弧度

正常状态:cancel_normal.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle" ><gradientandroid:angle="90"android:endColor="#EBEBEB"android:startColor="#EBEBEB" /><cornersandroid:bottomLeftRadius="5dp"android:bottomRightRadius="5dp"android:topLeftRadius="5dp"android:topRightRadius="5dp" />
</shape>

按下状态:cancel_pressed.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle" ><gradientandroid:angle="90"android:endColor="#CACACB"android:startColor="#CACACB" /><cornersandroid:bottomLeftRadius="5dp"android:bottomRightRadius="5dp"android:topLeftRadius="5dp"android:topRightRadius="5dp" />
</shape>

状态选择器:selector_cancel.xml

<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"><item android:drawable="@drawable/cancel_pressed" android:state_focused="true"/><item android:drawable="@drawable/cancel_pressed" android:state_focused="false" android:state_pressed="true"/><item android:drawable="@drawable/cancel_normal" android:state_focused="false"/></selector>

(4)对话框的布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:background="#00000000"android:gravity="bottom"android:orientation="vertical"android:padding="5dip" ><Buttonandroid:id="@+id/but_open_photo"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="@drawable/selector_gallery"android:paddingBottom="10dip"android:paddingTop="10dip"android:text="图库"android:textSize="16sp" /><TextViewandroid:layout_width="match_parent"android:layout_height="0.5dip"android:background="#DAD9DB" /><Buttonandroid:id="@+id/but_take_photo"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="@drawable/selector_camera"android:paddingBottom="10dip"android:paddingTop="10dip"android:text="拍照"android:textSize="16sp" /><Buttonandroid:id="@+id/but_cancel"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="5dip"android:background="@drawable/selector_cancel"android:paddingBottom="10dip"android:paddingTop="10dip"android:text="取消"android:textSize="16sp" /></LinearLayout>

布局效果:

2.对话框进出动画(anim文件夹中)

(1)对话框弹出动画dialog_in_anim.xml:(进出时长300ms)

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" ><translateandroid:duration="300"android:fromXDelta="0"android:fromYDelta="1000"android:toXDelta="0"android:toYDelta="0" /></set>

(2)对话框消失动画dialog_in_anim.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" ><translateandroid:duration="300"android:fromXDelta="0"android:fromYDelta="0"android:toXDelta="0"android:toYDelta="1000" /></set>

3.style.xml中添加样式

    <style name="style_anim_dialog"><item name="android:windowEnterAnimation">@anim/dialog_in_anim</item><item name="android:windowExitAnimation">@anim/dialog_out_anim</item></style>

二 主代码编写

此处将逻辑抽取到方法里,在需要的地方调用即可:

   /***对话框使用逻辑*/protected void showQQDialog() {//加载对话框布局View view = getLayoutInflater().inflate(R.layout.dialog_qq_item, null);final Dialog dialog = new Dialog(this);dialog.setContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));Window window = dialog.getWindow();//获取窗口window.setWindowAnimations(R.style.style_anim_dialog); // 设置显示动画//设置对话框背景为透明 <color name="trans">#00000000</color>window.setBackgroundDrawableResource(R.color.trans);WindowManager.LayoutParams wl = window.getAttributes();wl.y = getWindowManager().getDefaultDisplay().getHeight();// 以下这两句是为了保证按钮可以水平满屏wl.width = Toolbar.LayoutParams.MATCH_PARENT;wl.height = Toolbar.LayoutParams.WRAP_CONTENT;dialog.onWindowAttributesChanged(wl); // 设置显示位置dialog.setCanceledOnTouchOutside(true); // 设置点击外围解散dialog.show();//展示对话框view.findViewById(R.id.but_cancel).setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {dialog.dismiss();}});view.findViewById(R.id.but_open_photo).setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Intent intent = new Intent(Intent.ACTION_GET_CONTENT);intent.setType("image/*");startActivity(intent); //打开系统图库}});view.findViewById(R.id.but_take_photo).setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);startActivity(intent);// 打开系统拍照}});}

本项目源码地址:https://github.com/toly1994328/DialogTest

转载于:https://www.cnblogs.com/toly-top/p/9782043.html

自定义Dialog(QQ头像选择弹出的对话框)相关推荐

  1. 使用Android studio完成”仿QQ的头像选择弹出的对话框“步骤及知识梳理

    闲着无聊,提前请假回家闭关学习... 先看效果图: 该DEMO 是我网上找的,比较喜欢这个动画效果,就自己动手实现了一遍,原理不难,但是真正理解使用起来也不简单. 一:自定义Dialog 当你点击按钮 ...

  2. android选择头像弹窗,仿QQ的头像选择弹出的对话框

    这个例子是点击按钮后,选择菜单会从屏幕底部慢慢弹出来,按菜单以外的屏幕,菜单会消失. 先看一下效果吧. 对话框布局xml文件如下: android:layout_width="match_p ...

  3. Android自定义拍照上传界面,Android自定义dialog——设置头像(拍照,相册)

    Android自定义dialog--设置头像(拍照,相册) 需求场景:个人信息设置,点击头像,在界面上弹出一个弹框,用户选择"拍照"/"从图库选择",选择照片后 ...

  4. 可以弹出确认对话框的自定义Web服务器控件ConfirmButton

    作者:活靶子[原创]       出处:AspxBoy.Com 经常在论坛里看到类似这样的问题:"-如何在点击删除按钮的时候弹出个确认删除对话框". 下面我们来自己写一个这样的自定 ...

  5. messagrbox自定义按钮c语言,基于dialogbox修改可自定义按钮及事件的弹出框插件

    插件描述:基于dialogbox1.0修改可自定义按钮及事件的弹出框插件,每个按钮可绑定单独的触发事件,并且能支持将弹出框作为一个表单来填入数据并获取 $('body').dialogbox({ ty ...

  6. 图片上传时,QQ浏览器会弹出下载弹框的解决方案

    在做这次的欢乐购车季项目中,出现了一个以前没有遇到的问题,就是点击上传按钮,QQ浏览器会弹出下载框,非常讨厌.从网上查了很多资料,虽然大家对QQ浏览器带给前端的麻烦是深恶痛绝,但是没办法,还得想办法解 ...

  7. android一天一次弹窗,Android自定义Toast,多次弹出时取消上次弹出,最后一次弹出为准...

    下面是编程之家 jb51.cc 通过网络收集整理的代码片段. 编程之家小编现在分享给大家,也给大家做个参考. Android的Toast用队列管理弹出的消息,这个自定义的Toast用于频繁弹出Toas ...

  8. html5仿qq空间,JS实现的仿QQ空间图片弹出效果代码

    本文实例讲述了JS实现的仿QQ空间图片弹出效果代码.分享给大家供大家参考,具体如下: function imageShow(which_click) { var image_path = which_ ...

  9. 仿qq等右上角弹出气泡菜单效果

    仿QQ右上角的弹出菜单框 博客同步自:个人博客主页 Screenshots How to Use step 1 Add the JitPack repository to your build fil ...

最新文章

  1. php 图片处理类,分享php多功能图片处理类
  2. Angularjs与weui的握手
  3. QT中文显示乱码解决
  4. Ubuntu下取消MySQL自动启动
  5. 【✈️️️排序算法,一文讲尽!Top 10 Sort Algorithms✈️️️】C/C++ 实现经典十大排序算法
  6. Kilani and the Game
  7. boost::mp11::mp_for_each相关用法的测试程序
  8. ITK:预定义操作以对应两个图像中的像素
  9. date样式找不到_涡轮+国VI排放,顶配售价不到12万,家用轿车看它准没错
  10. python自动生成word版本试卷_Python解决问题:生成包含加减练习题的Word文件
  11. html字居右垂直设置,css文字水平垂直居中怎么设置?
  12. 使用Swagger UI的Document和Test API
  13. 将mbr的分区改为gpt分区
  14. chrome样式不生效_Chrome开发者工具的11个使用技巧
  15. Hive 安装配置及下载地址
  16. 软件详细设计文档(终)
  17. ipad能不能装python_ipad能下载python么
  18. 怎么判断时double和floatc++_痛心!血肌酐正常却已经肾衰?如何判断肾功能,这些指标更准确...
  19. MT9630/9632 遥控器配置
  20. 这5个PNG免抠素材网站,可商用,赶紧马住了

热门文章

  1. c#网络通信框架networkcomms内核解析之七 数据包创建器(PacketBuilder)
  2. 异或运算规则以及应用
  3. Mac M1 搭建 React Native 环境
  4. sersync+rsync原理及部署
  5. Ext.XTemplate加载拥有头像的用户
  6. 为什么PHP项目运行报错502,PHP的502报错
  7. 玩游戏玩久了手机发烫卡顿怎么办?LDR6020方案助力手机散热器 实现快速降温
  8. 通信工程馈线制作心得
  9. SDUT3930 - 皮卡丘的梦想2(线段树状态压缩)
  10. 金额达 500 亿美元,AMD 完成收购赛灵思