自定义底部弹出的PopupWindow【So Easy!】
第一步:
创建自己的xml文件。
<?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="wrap_content" android:background="@color/white" android:orientation="vertical"> <LinearLayout android:id="@+id/details_comment" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@mipmap/comui_bar_top_shadow" /> <LinearLayout android:layout_width="match_parent" android:layout_height="0px" android:layout_weight="1" android:minHeight="100px" android:gravity="center_vertical" android:orientation="horizontal" android:paddingLeft="30px" android:paddingRight="30px"> <EditText android:id="@+id/details_comment_edit" android:layout_width="0px" android:layout_height="60px" android:layout_weight="1" android:background="@drawable/shape_search" android:gravity="center_vertical" android:hint="请输入评论" android:maxLength="3" android:paddingLeft="20px" android:paddingRight="20px" android:textSize="28px" android:textColorHint="#666666" /> <TextView android:id="@+id/details_comment_submit" android:layout_width="120px" android:layout_height="50px" android:layout_marginLeft="20px" android:background="@drawable/shape_getcode" android:gravity="center" android:text="发送" android:textColor="@color/colorAccent" android:textSize="30px" /> </LinearLayout> </LinearLayout> </LinearLayout>
第二步:
上代码:
View view = View.inflate(getContext(), R.layout.popup_comment, null); //此处可按需求为各控件设置属性 view.findViewById(R.id.details_comment_submit).setOnClickListener(new View.OnClickListener() {@Override public void onClick(View view) {} }); AutoUtils.auto(view); PopupWindow popupWindow = new PopupWindow(view); //设置弹出窗口大小 popupWindow.setWidth(WindowManager.LayoutParams.FILL_PARENT); popupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT); //必须设置以下两项,否则弹出窗口无法取消 popupWindow.setFocusable(true); popupWindow.setBackgroundDrawable(new ColorDrawable(0x00000000)); //设置动画效果 popupWindow.setAnimationStyle(R.style.AnimBottom); //设置显示位置,findViewById获取的是包含当前整个页面的view popupWindow.showAtLocation(add, Gravity.BOTTOM, 0, 0);
解释:
1.
View view = View.inflate(getContext(), R.layout.popup_comment, null);
其中的popup_comment即为自定义的PopupWindow中的xml文件。
2.
popupWindow.setAnimationStyle(R.style.AnimBottom);
这个地方为设置动画效果。
第一步:
在style文件中加入:
<style name="AnimBottom" parent="@android:style/Animation"> <item name="android:windowEnterAnimation">@anim/push_bottom_in</item> <item name="android:windowExitAnimation">@anim/push_bottom_out</item> </style>
第二步:
在res文件夹下,创建anim文件夹。
在anim文件夹里面创建push_bottom_in.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:duration="200" android:fromYDelta="50%p" android:toYDelta="0" /> </set>
在anim文件夹里面创建push_bottom_out.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:duration="200" android:fromYDelta="0" android:toYDelta="50%p" /> </set>
3.
popupWindow.showAtLocation(findViewById(R.id.comment), Gravity.BOTTOM, 0, 0);
这个地方的findViewById(R.id.comment),为你要显示到的地方的控件。
自定义底部弹出的PopupWindow【So Easy!】相关推荐
- html自定义js程序,JS中微信小程序自定义底部弹出框
实现微信小程序底部弹出框效果,代码分为html,css和js两部分,具体代码详情大家参考下本文. html CSS .commodity_screen { width: 100%; height: 1 ...
- android的底部弹出框炫酷的样式,Android自定义底部弹出框ButtomDialog
本文实例为大家分享了Android自定义底部弹出框的具体代码,供大家参考,具体内容如下 先看看效果和你要的是否一样 一 .先来配置自定义控件需要的资源 1.在res文件夹下创建一个anim文件夹并创建 ...
- Android自定义底部弹出窗-dialog(2种实现分析+源码)
Android自定义底部弹出窗-dialog(2种实现分析+源码) 上线项目功能抽取,在项目开发中,我们会在许多地方会用到底部自定义弹窗,比如设置:个人账户退出,切换,照片的拍照或者相册的调出,或者一 ...
- Android——完全自定义 底部弹出支付页面
近期博主在网上随便搜了一番,发现很多实现 底部弹出支付页面的大多数都用的,自定义PopupWindow 去实现的,里面复杂的逻辑看得我不想看,很多对自定义不熟悉伙伴们,看到 自定义 这三个字就有种血脉 ...
- 微信小程序 -- 自定义底部弹出框(带动画--滑入滑出)
实现这么一个功能,点击选项进行选择,效果是从底部弹出选项框(带滑出动画),选择了某项或者点击其他地方,隐藏(带滑出动画).效果图如下: 可适用于任何场景,如普通选项(如图)或者类似商城小程序选择商品属 ...
- android 自定义spnner弹出框,PopupWindow,ListView实现自定义Spinner
最终的效果图,点击+86弹出popup 这里写图片描述 PupupWindow的布局文件 为一个ListView 作为pupup的主体内容 android:orientation="vert ...
- [RN] React Native 自定义 底部 弹出 选择框 实现
React Native 自定义 底部选择框 实现 效果如图所示: 实现方法: 一.组件封装 CustomAlertDialog.js import React, {Component} from ' ...
- 自定义底部弹出Dialog(老掉牙的需求还是记录一下吧)
(1)布局: phonto_dialog.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/and ...
- Android底部弹出选择框PickerView的使用
希望大家可以留个关注点赞,后续会有更多的技术分享 前言 本次主要介绍Android中底部弹出框的使用,使用两个案例来说明,首先是时间选择器,然后是自定义底部弹出框的选择器,以下来一一说明他们的使用方法 ...
最新文章
- 使用RabbitMQ做数据接收和处理时,自动关闭
- 上交大张拳石:深度学习可解释性,从百家争鸣到合众归一
- python制作工资计算器-Python实现扣除个人税后的工资计算器示例
- css家用电器,家用电器
- VS code配置docker的shell环境
- Android App列表之游标ListView(索引ListView)
- ibatis(0)ibatis 与 mybatis 简述
- 在的微型计算机系统中 外设可和,微机原理第七章题库
- 广色域图片Android,Android Q将支持广色域照片
- CodeProject的网站
- socket连接测试工具,window和linux下
- 基于激光雷达的3D实时车辆跟踪
- GoldWave2020注册激活码版下载音频处理制作教程
- 自动控制——2、为什么用微分方程来表示线性定常系统
- java poi html转PDF_实现word转pdf,HTML转pdf(探索篇)
- Wagtail Usage guide:Wagtail 使用指南
- Flask的Jinjia2模板
- elasticsearch 支持拼音检索
- ip 华三secondary_H3C交换机配置端口IP sub实例
- 【播放器】播放器对比