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 ...
随机推荐
- ajax操作提交整个表单内容
1 2 3 4 5 6 7 8 9 10 11 12 13 $.ajax({ cache: true, type: "POST ...
- 被动路由跟踪工具InTrace
被动路由跟踪工具InTrace InTrace是一款类似于Traceroute的路由跟踪工具.但它不同的是,他不主动发送数据包,而是通过监听当前主机和目标主机的数据包,进行分析,从而获取路由信息. ...
- Excel文件处理Demo
1.BLL业务逻辑代码 /// <summary> /// 处理“店铺竞品销售数据”导入文件 /// </summary> /// <param name="f ...
- javascript --- 继承小结
回顾之前学到的知识,大体上可以分为两类: 1. 基于构造器工作的模式. 2. 基于对象的工作模式. 3. 是否使用原型 4. 是否执行属性拷贝. 5. 两者都有(执行原型属性拷贝) 下面我们把之前的知 ...
- Android获取窗口可视区域大小: getWindowVisibleDisplayFrame()
getWindowVisibleDisplayFrame()方法 getWindowVisibleDisplayFrame()是View类下的一个方法,从方法的名字就可以看出,它是用来获取当前窗口可视 ...
- sql的一些知识_where
简单相同查询,查询age=22的三列信息,并按照降序排列 ORDER BY weight DESC 此外,where还支持一下判断操作符 值得注意的是,如果比较的值为数值,则不需要加引号,如果是字符, ...
- node开发自动刷新网页中的css和javascript
在已有node的环境下,安装browser-sync: npm install -g browser-sync 然后运行,默认本目录下(最后填写要监听的文件--本实例监听了css文件夹下面的所有css ...
- 关于CUDA两种API:Runtime API 和 Driver API
CUDA 眼下有两种不同的 API:Runtime API 和 Driver API,两种 API 各有其适用的范围. 高级API(cuda_runtime.h)是一种C++ ...
- 实现TextView中link的点击效果
朋友们,你们在TextView处理link的时候是不是一直被苦逼的android默认的方式困扰?每次点击link的时候,点击效果是整个textview来响应.非常烂吧?原因就不多赘述了. 那么以下这个 ...
- 可在 html5 游戏中使用的 js 工具库
可在 html5 游戏中使用的 js 工具库 作者: 木頭 时间: September 21, 2014 分类: Utilities,Game 使用 cocos2d-js 3.0 开发游戏项目两三个月 ...