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 ...
随机推荐
- Linux内存管理【转】
转自:http://www.cnblogs.com/wuchanming/p/4360264.html 转载:http://www.kerneltravel.net/journal/v/mem.htm ...
- 写一简单kernel心得
当人按下笔记本开机键时.cpu的cs寄存器(基址)跟ip(偏移量)寄存器加电.被强制初始化为(jmp xxx:xxx) 跳转到bios所在的地址. 接着bios开机自检(这个不需要了解,只需了解最后跳 ...
- php 几种排序模式
冒泡排序 冒泡排序(Bubble Sort,台湾译为:泡沫排序或气泡排序)是一种简单的排序算法.它重复地走访过要排序的数列,一次比较两个元素,如果他们的顺序错误就把他们交换过来.走访数列的工>作 ...
- sql server2008 R2安装总结
1,卸载注意 在卸载Microsoft SQL Server 2008 R2 安装程序(简体中文) 出现 :“警告 26003.无法卸载 Microsoft SQL Server 2008 R2 安装 ...
- hdu3947 给一些已知(需费用)路径去覆盖一些边 //预先加灌法费用流
River Problem 题意:一个有向树(河流),只有一个汇点1,每条边只有一个出度.有些河道有污染指数xi,必需要治理,有m段路径,可以去覆盖这些,每被覆盖一次,xi降低响应值. :即 给出一些 ...
- Ajax的post方式提交数据
最新需要学习如何使用 POST 提交方法的接口,正好看到了Ajax 版本的感觉不错分享给大家,欢迎高手指点. <SCRIPT LANGUAGE=”javascript”> <!– f ...
- 快速构造FFT/NTT
@(学习笔记)[FFT, NTT] 问题概述 给出两个次数为\(n\)的多项式\(A\)和\(B\), 要求在\(O(n \log n)\)内求出它们的卷积, 即对于结果\(C\)的每一项, 都有\[ ...
- openssl转换各种证书的语法收集
参考网址:https://www.sslshopper.com/ssl-converter.html 个人总结:先找准要生成什么证书先,尤其是正规购买的流程与openssl生成的不一样,所以先确定是什 ...
- 为VLC增加在线字幕插件VLSub
VLC的在在线字幕插件VLSub,官网:https://github.com/exebetche/vlsub. 原理是通过搜索全球最大的字幕网站https://www.opensubtitles.or ...
- 黑科技:CSS定制多行省略
转载请注明出处:http://hai.li/2017/03/08/css-multiline-overflow-ellipsis.html 什么是多行省略? 当字数多到一定程度就显示省略号点点点.最初 ...