Android笔记之自定义PopupWindow
效果图

popup_window_addition.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@mipmap/addition_popup_window_background"
android:orientation="vertical"
android:paddingLeft="20dp"
android:paddingTop="15dp"
android:paddingRight="15dp"> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginBottom="15dp"
android:drawableLeft="@mipmap/ic_chat"
android:drawablePadding="15dp"
android:gravity="center"
android:text="发起群聊"
android:textColor="@android:color/white" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
android:drawableLeft="@mipmap/ic_add_friend"
android:drawablePadding="15dp"
android:gravity="center"
android:text="添加朋友"
android:textColor="@android:color/white" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
android:drawableLeft="@mipmap/ic_scan"
android:drawablePadding="15dp"
android:gravity="center"
android:text="扫一扫"
android:textColor="@android:color/white" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
android:drawableLeft="@mipmap/ic_receive_pay"
android:drawablePadding="15dp"
android:gravity="center"
android:text="收付款"
android:textColor="@android:color/white" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
android:drawableLeft="@mipmap/ic_feedback"
android:drawablePadding="15dp"
android:gravity="center"
android:text="帮助与反馈"
android:textColor="@android:color/white" />
</LinearLayout>
AdditionPopupWindow.java
package com.bu_ish.popup_window_example; import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.PopupWindow; public class AdditionPopupWindow extends PopupWindow {
public AdditionPopupWindow(Context context) {
setWidth(LinearLayout.LayoutParams.WRAP_CONTENT);
setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
setBackgroundDrawable(new ColorDrawable());
setOutsideTouchable(true);
View view = LayoutInflater.from(context).inflate(R.layout.popup_window_addition, null);
setContentView(view);
}
}
MainActivity.java
package com.bu_ish.popup_window_example; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View; public class MainActivity extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.addImageView).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AdditionPopupWindow popupWindow = new AdditionPopupWindow(MainActivity.this);
popupWindow.showAsDropDown(v);
}
});
}
}
注意
要想点击外部关闭PopupWindow,必须调用setBackgroundDrawable(Drawable)和setOutsideTouchable(boolean)
完整Demo链接:https://pan.baidu.com/s/1NF5-SUaOyHOWRWCFKfTWCA,提取码:c59o
Android笔记之自定义PopupWindow的更多相关文章
- Android笔记之自定义对话框
效果如下图 对话框布局 dialog_uninstallation_confirmation.xml <?xml version="1.0" encoding="u ...
- Android笔记之自定义的RadioGroup、RadioButton,以及View实例状态的保存与恢复
效果图 activity_main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLay ...
- Android 自定义PopupWindow动画效果
public class RollActivity extends Activity { private View view; private Button btn; private PopupWin ...
- Android学习笔记_34_自定义窗口标题
1.建好项目之后在它的layout文件夹下创建一个title.xml文件,作为自定义窗口标题的文件. <?xml version="1.0" encoding="u ...
- 自定义PopupWindow弹出框(带有动画)
使用PopupWindow来实现弹出框,并且带有动画效果 首先自定义PopupWindow public class LostPopupWindow extends PopupWindow { pub ...
- Android笔记:触摸事件的分析与总结----TouchEvent处理机制
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://glblong.blog.51cto.com/3058613/1559320 ...
- 自定义PopupWindow动画效果
public class RollActivity extends Activity { private View view; private Button btn; private PopupWin ...
- 我的Android进阶之旅------>Android如何通过自定义SeekBar来实现视频播放进度条
首先来看一下效果图,如下所示: 其中进度条如下: 接下来说一说我的思路,上面的进度拖动条有自定义的Thumb,在Thumb正上方有一个PopupWindow窗口,窗口里面显示当前的播放时间.在Seek ...
- Android笔记--View绘制流程源码分析(一)
Android笔记--View绘制流程源码分析 View绘制之前框架流程分析 View绘制的分析始终是离不开Activity及其内部的Window的.在Activity的源码启动流程中,一并包含 着A ...
随机推荐
- (转):从内核代码聊聊pipe的实现
来源: http://luodw.cc/2016/07/09/pipeof/ 用linux也有两年多了,从命令,系统调用,到内核原理一路学过来,我发现我是深深喜欢上这个系统:使用起来就是一个字&quo ...
- webUpload上传插件的一些bug
当你给上传按钮的父级或当前元素添加一个display:none时 你可能遇到了这样的一个问题.当你在点击显示这个按钮时 你发现按钮失效了 你需要点击F12才可以. flash 版本太低,请至少大于等于 ...
- Ruby自动化测试(操作符的坑)
事情是这样的: times++ @ddr = DDR::DDR.new() 执行到这里的时候,总是报错:'+@' undefied method.刚开始的时候以为是机器在重启过程中一些不稳定函数调用或 ...
- AC日记——魔术球问题 洛谷 P2765
题目描述 «问题描述: 假设有n根柱子,现要按下述规则在这n根柱子中依次放入编号为1,2,3,...的球. (1)每次只能在某根柱子的最上面放球. (2)在同一根柱子中,任何2个相邻球的编号之和为完全 ...
- MySQL创建存储过程/函数需要的权限
alter routine---修改与删除存储过程/函数 create routine--创建存储过程/函数 execute--调用存储过程/函数 下面有一篇介绍MySQL所有权限的博文 http:/ ...
- 51nod 1201 整数划分
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1201 DP转移方程:dp[i][j] = dp[i-j][j]+dp[i ...
- SRM1153
SRM 711 DIV1 <br > 250 ConsecutiveOnes 位数不会很多,直接暴枚 直接在\(n\)的基础上修改,暴枚修改的区间,显然,位置先于暴力修改区间的位置不需要改 ...
- 配置tomcat启动参数-Dfile.encoding=UTF-8后,IDEA控制台乱码
配置tomcat启动参数-Dfile.encoding=UTF-8后,IDEA控制台出现乱码 解决方法: 在idea的bin目录(如:D:\JetBrains\IntelliJ IDEA 2018.1 ...
- Window10下Apache2.4的安装和运行
以前用Python运行的Web框架都是要运行在Linux下,加上WSGI服务器,比如Gunicorn+Flask,后来了解到了Apache,看看能不能基于Apache这个Web服务器下给python提 ...
- jquery的ajax的success和fail用法
$.ajax({ type:"POST", url: url, contentType: 'application/json;charset=utf-8', data: JSON. ...