全网整合营销服务商

电脑端+手机端+微信端=数据同步管理

免费咨询热线:400-708-3566

Android简单实现自定义弹框(PopupWindow)

一:一般都是先上效果图

二:实现步骤:

1.xml布局实现

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:background="@drawable/store_bgimg">
 <RelativeLayout
 android:layout_width="fill_parent"
 android:layout_height="214dp"
 android:layout_centerVertical="true"
 android:layout_marginLeft="31dp"
 android:layout_marginRight="31dp"
 android:background="@drawable/tkbjzj">
 <TextView
  android:id="@+id/tetle"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_centerHorizontal="true"
  android:layout_marginTop="26dp"
  android:text="七天连锁酒店"
  android:textColor="#262626"
  android:textSize="18dp" />
 <TextView
  android:id="@+id/textdz"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_below="@+id/tetle"
  android:layout_centerHorizontal="true"
  android:layout_marginTop="34dp"
  android:text="你已领取本店7.5折优惠券"
  android:textColor="#ea302e" />
 <View
  android:layout_width="match_parent"
  android:layout_height="0.5dp"
  android:layout_above="@+id/lineardb"
  android:background="#e6e6e6" />
 <LinearLayout
  android:id="@+id/lineardb"
  android:layout_width="match_parent"
  android:layout_height="44dp"
  android:layout_alignParentBottom="true">
  <TextView
  android:id="@+id/textwzdl"
  android:layout_width="0dp"
  android:layout_height="fill_parent"
  android:layout_weight="1"
  android:gravity="center"
  android:text="我知道了"
  android:textColor="#262626"
  android:textSize="16dp" />
  <TextView
  android:id="@+id/textckxq"
  android:layout_width="0dp"
  android:layout_height="fill_parent"
  android:layout_weight="1"
  android:background="#f86c6a"
  android:gravity="center"
  android:text="查看详情"
  android:textColor="#ffffff"
  android:textSize="16dp" />
 </LinearLayout>
 </RelativeLayout>
</RelativeLayout>

2.drawable文件下的转角,然后在布局引用

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
 <!-- 背景颜色 -->
 <solid android:color="#ffffff" />
 <!-- 控制边界线颜色和大小 -->
 <stroke
 android:width="1dp"
 android:color="#ffffff" />
 <!-- 控制圆角大小 -->
 <corners android:radius="4dp" />
</shape>

3.activity的实现

/**
 * 弹框
 */
private View mPopupHeadViewy;//创建一个view
private PopupWindow mHeadPopupclly;//PopupWindow
private TextView tetle, textdz;//title,打折
private TextView textwzdl, textckxq;//我知道了,查看详情
@SuppressWarnings("deprecation")
private void popupHeadWindowcll() {
 mPopupHeadViewy = View.inflate(getActivity(), R.layout.tankuang_layout, null);
 tetle = (TextView) mPopupHeadViewy.findViewById(R.id.tetle);
 textdz = (TextView) mPopupHeadViewy.findViewById(R.id.textdz);
 textwzdl = (TextView) mPopupHeadViewy.findViewById(R.id.textwzdl);
 textckxq = (TextView) mPopupHeadViewy.findViewById(R.id.textckxq);
 mHeadPopupclly = new PopupWindow(mPopupHeadViewy, AbsListView.LayoutParams.MATCH_PARENT, AbsListView.LayoutParams.MATCH_PARENT, true);
 // 在PopupWindow里面就加上下面代码,让键盘弹出时,不会挡住pop窗口。
 mHeadPopupclly.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
 mHeadPopupclly.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
 mHeadPopupclly.setBackgroundDrawable(new BitmapDrawable());
 mHeadPopupclly.setOutsideTouchable(true);
 mHeadPopupclly.showAsDropDown(textviewid, 0, 0);
 textwzdl.setOnClickListener(new View.OnClickListener() {
 @Override
 public void onClick(View v) {
  mHeadPopupclly.dismiss();
 }
 });
 textckxq.setOnClickListener(new View.OnClickListener() {
 @Override
 public void onClick(View v) {
  mHeadPopupclly.dismiss();
  Toast.makeText(getActivity(), "查看详情", Toast.LENGTH_LONG).show();
 }
 });
}

注意:

1、

mHeadPopupclly = new PopupWindow(mPopupHeadViewy, AbsListView.LayoutParams.MATCH_PARENT, AbsListView.LayoutParams.MATCH_PARENT, true);

这句代码就是控制弹出框是铺满屏幕还是自适应

2、

mHeadPopupclly.showAsDropDown(textviewid, 0, 0);

这句话是这个弹框基于哪个控件之下,textviewid是控件名,后面两个是坐标

这是一个简单的自定义弹框,大神勿喷,有用的希望顶一下

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持!


# android  # 自定义弹框  # 自定义popupwindow  # Android高德地图marker自定义弹框窗口  # Android自定义弹框样式  # Android启动页用户相关政策弹框的实现代码  # Android 实现抖音头像底部弹框效果的实例代码  # Android中 TeaScreenPopupWindow多类型筛选弹框功能的实例代码  # android自定义Dialog弹框和背景阴影显示效果  # Android 提交或者上传数据时的dialog弹框动画效果  # 浅析Android中常见三种弹框在项目中的应用  # Android填坑系列:在小米系列等机型上放开定位权限后的定位请求弹框示例  # Android自定义弹框Dialog效果  # 查看详情  # 弹出  # 我知道了  # 都是  # 这是一个  # 这句话  # 大神  # 自定义  # 这句  # 创建一个  # 自适应  # 铺满  # 圆角  # id  # TextView  # fill_parent  # layout_marginLeft  # wrap_content  # tetle  # tkbjzj 


相关文章: 如何在西部数码注册域名并快速搭建网站?  教育培训网站制作流程,请问edu教育网站的域名怎么申请?  视频网站app制作软件,有什么好的视频聊天网站或者软件?  开心动漫网站制作软件下载,十分开心动画为何停播?  建站之星北京办公室:智能建站系统与小程序生成方案解析  青浦网站制作公司有哪些,苹果官网发货地是哪里?  公司门户网站制作公司有哪些,怎样使用wordpress制作一个企业网站?  ,怎么用自己头像做动态表情包?  视频网站制作教程,怎么样制作优酷网的小视频?  如何在Windows服务器上快速搭建网站?  在线教育网站制作平台,山西立德教育官网?  python的本地网站制作,如何创建本地站点?  如何在Golang中处理模块冲突_解决依赖版本不兼容问题  如何高效搭建专业期货交易平台网站?  安徽网站建设与外贸建站服务专业定制方案  学校免费自助建站系统:智能生成+拖拽设计+多端适配  建站之星伪静态规则如何正确配置?  网站广告牌制作方法,街上的广告牌,横幅,用PS还是其他软件做的?  三星网站视频制作教程下载,三星w23网页如何全屏?  如何快速登录WAP自助建站平台?  潍坊网站制作公司有哪些,潍坊哪家招聘网站好?  杭州银行网站设计制作流程,杭州银行怎么开通认证方式?  网站设计制作企业有哪些,抖音官网主页怎么设置?  如何快速搭建支持数据库操作的智能建站平台?  企业网站制作费用多少,企业网站空间一般需要多大,费用是多少?  电商平台网站制作流程,电商网站如何制作?  如何选择高效响应式自助建站源码系统?  购物网站制作公司有哪些,哪个购物网站比较好?  网站制作大概要多少钱一个,做一个平台网站大概多少钱?  南平网站制作公司,2025年南平市事业单位报名时间?  C#怎么创建控制台应用 C# Console App项目创建方法  网站专业制作公司有哪些,做一个公司网站要多少钱?  文字头像制作网站推荐软件,醒图能自动配文字吗?  如何在香港免费服务器上快速搭建网站?  自助网站制作软件,个人如何自助建网站?  东莞专业网站制作公司有哪些,东莞招聘网站哪个好?  移民网站制作流程,怎么看加拿大移民官网?  如何有效防御Web建站篡改攻击?  网站制作软件有哪些,制图软件有哪些?  广州网站设计制作一条龙,广州巨网网络科技有限公司是干什么的?  如何通过宝塔面板实现本地网站访问?  手机网站制作平台,手机靓号代理商怎么制作属于自己的手机靓号网站?  高端企业智能建站程序:SEO优化与响应式模板定制开发  公司网站制作价格怎么算,公司办个官网需要多少钱?  5种Android数据存储方式汇总  如何在阿里云虚拟主机上快速搭建个人网站?  mc皮肤壁纸制作器,苹果平板怎么设置自己想要的壁纸我的世界?  如何通过网站建站时间优化SEO与用户体验?  建站之星代理平台如何选择最佳方案?  教学网站制作软件,学习*后期制作的网站有哪些? 

您的项目需求

*请认真填写需求信息,我们会在24小时内与您取得联系。