第一步:

private PopupWindow mPopupWindow;

第二步:写一个popupwindow的布局文件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="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#669E9E9E">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#E4E4E4"
>
<TextView
android:id="@+id/popupwindow_Jan"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="一月份"
android:gravity="center"
/>
<TextView
android:id="@+id/popupwindow_Feb"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="二月份"
android:gravity="center"
/>
<TextView
android:id="@+id/popupwindow_Mar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="三月份"
android:gravity="center"
/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
第三步:在Activity写代码
public void onClick(View v) {
switch (v.getId()) {
case R.id.home_travel_modes_yuefen_textview:
showPopupWindow(v);
break;
case R.id.popupwindow_Jan:
showToastMsg("一月份");
break;
case R.id.popupwindow_Feb:
showToastMsg("二月份");
break;
default:
break;
}
 public void showPopupWindow(View v){
View contentView = LayoutInflater.from(HomeTravelModesActivity.this).inflate(R.layout.home_popuplayout, null);
TextView JanText = (TextView)contentView.findViewById(R.id.popupwindow_Jan);
TextView FebText = (TextView)contentView.findViewById(R.id.popupwindow_Feb);
TextView MarText = (TextView)contentView.findViewById(R.id.popupwindow_Mar);
JanText.setOnClickListener(this);
FebText.setOnClickListener(this);
MarText.setOnClickListener(this);
final PopupWindow popupWindow = new PopupWindow(contentView,
LinearLayout.LayoutParams.MATCH_PARENT, 300, true);
popupWindow.setTouchable(true); // popupWindow.setTouchInterceptor(new View.OnTouchListener() {
//
// @Override
// public boolean onTouch(View v, MotionEvent event) {
//
// Log.i("mengdd", "onTouch : ");
//
// return false;
// // 这里如果返回true的话,touch事件将被拦截
// // 拦截后 PopupWindow的onTouchEvent不被调用,这样点击外部区域无法dismiss
// }
// });
// 如果不设置PopupWindow的背景,无论是点击外部区域还是Back键都无法dismiss弹框
// 我觉得这里是API的一个bug
popupWindow.setBackgroundDrawable(getResources().getDrawable(
R.mipmap.ic_launcher));
// 设置好参数之后再show
popupWindow.showAsDropDown(v);
}
注:
若在Activity的onCreate()方法中直接写弹出PopupWindow()方法报错,因为Activity没有完全启动是不能弹出PopupWindow的,那我们只需要在Activity完全启动后在弹出PopupWindow就行了。
重写一下onWindowFocusChanged()方法:
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
//弹出PopupWindow的具体代码
}
												

Popupwindow 的简单实用,(显示在控件下方)的更多相关文章

  1. Android自定义PopupWindow显示在控件上方或者下方

    记录学习之用 View view = mInflater.inflate(R.layout.layout_popupwindow, null); PopUpwindowLayout popUpwind ...

  2. ASP.NET AjaxControlToolkit-Framework4.0 配置实用(简单介绍CalendarExtender日期控件)

    1:下载:AjaxControlToolkit Ajax Control Toolkit .NET 4 Ajax Control Toolkit .NET 4.5 Ajax Control Toolk ...

  3. Winform开发框架之肖像显示保存控件的实现

    我们在开发一些Winform程序的时候,除了常规的显示普通数据外,有的时候需要显示一些人员肖像或者一些车辆等物体的图片,一般这些内容较小,所以以二进制存储在数据库是一个不错的方案.但由于它们虽然很常用 ...

  4. WPF教程十一:简单了解并使用控件模板

    WPF教程十一:简单了解并使用控件模板 这一章梳理控件模板,每个WPF控件都设计成无外观的,但是行为设计上是不允许改变的,比如使用Button的控件时,按钮提供了能被点击的内容,那么自由的改变控件外观 ...

  5. [转]一种简单的js时间控件

    使用方法: 粘贴代码到文本文档中,文档名称为datetime.js,然后在html文件中引用如下代码即可 <input name="shijian1" id="sh ...

  6. (转)sl简单自定义win窗体控件

    sl简单自定义win窗体控件      相信大家接触过不少win窗体控件ChildWin子窗口就的sl自带的一个  而且网上也有很多类似的控件,而今天我和大家分享下自己制作个win窗体控件,希望对初学 ...

  7. 【转】silverlight telerik RadGridView 列头显示其他控件

    <telerik:GridViewDataColumn DataMemberBinding="{Binding target_id}" IsFilterable=" ...

  8. AngularJS进阶(七)实现根据不同条件显示不同控件

    AngularJS实现根据不同条件显示不同控件 由于项目需求,需要实现根据不同条件显示不同控件的功能.具体要求如下图所示: 即当选择"每单固定减"时,下方只显示"减免金额 ...

  9. BitmapImage处理网络图片,例如阿里云获取的图片。异步加载到需要显示的控件上。提升速度非常明显。

    想直接把网络图片赋给控件,又要下载又要缓存,速度非常慢.不流畅. 需要进行处理,异步加载会显著提升速度.方法如下: public static BitmapImage ByteArrayToBitma ...

随机推荐

  1. 16~25.spring+hibernate简单实例 .连接数据库并进行增删改查

    1.概念 Hibernate是一个开放源代码的对象关系映射框架,它对JDBC进行了非常轻量级的对象封装,它将POJO与数据库表建立映射关系,是一个全自动的orm框架,hibernate可以自动生成SQ ...

  2. CentOs7 网卡出现问题Job for network.service failed

    centos7网卡是需要写入MAC地址的不然启动不了 在运行“/etc/init.d/network restart”命令时,出现错误“Job for network.service failed.  ...

  3. 从json传递数据显示表格实例

    @interface ViewController ()<UITableViewDataSource,UITableViewDelegate> { UITableView* table; ...

  4. HDU 1000 & HDU1001 & 字符串连接

    A + B Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  5. hiho一下第一周 最长回文子串

    题目链接:http://hihocoder.com/contest/hiho1/problem/1 #include <iostream> #include <cstdio> ...

  6. mongoDB 3.0以前版本 - 入门指南、示例

    一.准备工作 1. 下载mongoDB 下载地址:http://www.mongodb.org/downloads 选择合适你的版本 相关文档:http://www.mongodb.org/displ ...

  7. Warp divergence

    Threads are executed in warps of 32, with all threads in the warp executing the same instruction at ...

  8. ASP.NET SignalR 与 LayIM2.0 配合轻松实现Web聊天室(三) 之 实现单聊,群聊,发送图片,文件。

    上篇讲解了如何搭建聊天服务器,以及客户端js怎么和layui的语法配合.服务器已经连接上了,那么聊天还会远吗? 进入正题,正如上一篇提到的我们用 Client.Group(groupId)的方法向客户 ...

  9. nyoj744(位运算)

    题目:http://acm.nyist.net/JudgeOnline/problem.php?pid=744 思路:a^b可以得到a~b间任意两个数异或运算的长度的最大值,设为n,答案为:pow(2 ...

  10. ROW_NUMBER()函数的使用

    SQL Server数据库ROW_NUMBER()函数的使用是本文我们要介绍的内容,接下来我们就通过几个实例来一一介绍ROW_NUMBER()函数的使用. 实例如下: .使用row_number()函 ...