1>写好布局

<?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="@color/colorPrimary"
android:orientation="vertical" > <LinearLayout
android:id="@+id/edit_alarm"
android:layout_width="match_parent"
android:layout_height="60dp"> <ImageView
android:layout_width="24dp"
android:layout_marginLeft="16dp"
android:layout_height="match_parent"
android:src="@drawable/ic_alarm_add"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/edit_alarm"
style="@style/popupwindow_text_style"/> </LinearLayout> <View
android:layout_width="220dp"
android:layout_height="1dp"
android:background="?android:attr/listDivider" />
<LinearLayout
android:id="@+id/clear_alarm"
android:layout_width="match_parent"
android:layout_height="60dp"
>
<ImageView
android:layout_width="24dp"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:src="@drawable/ic_alarm_off"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/popupwindow_text_style"
android:text="@string/clear_alarm" /> </LinearLayout> </LinearLayout>

2>代码:

public void showAlarmPopupWindow() {
View view = LayoutInflater.from(getContext()).inflate(R.layout.alarm_popupwindow , null ,false);
LinearLayout editLayout = (LinearLayout)view.findViewById(R.id.edit_alarm);
LinearLayout clearLayout = (LinearLayout)view.findViewById(R.id.clear_alarm); final PopupWindow popupWindow = new PopupWindow(view , ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT , true); editLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
popupWindow.dismiss();
mPresenter.editAlarm();
}
});
clearLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
popupWindow.dismiss();
mPresenter.clearAlarm();
}
});
popupWindow.setAnimationStyle(android.R.style.Animation_Dialog);
popupWindow.showAsDropDown(getActivity().findViewById(R.id.toolbar) , getActivity().getWindowManager().getDefaultDisplay().getWidth() - popupWindow.getWidth() , 1);
}

PopupWindow的基本使用的更多相关文章

  1. Android PopupWindow Dialog 关于 is your activity running 崩溃详解

    Android PopupWindow Dialog 关于 is your activity running 崩溃详解 [TOC] 起因 对于 PopupWindow Dialog 需要 Activi ...

  2. Android popupwindow使用心得(一)

    最近项目中好多地方用到popupwindow,感觉这个控件还是非常重要的.所以把使用心得总结下,废话不多说,直接上代码. public class MainActivity extends Activ ...

  3. 不得不吐槽的Android PopupWindow的几个痛点(实现带箭头的上下文菜单遇到的坑)

    说到PopupWindow,我个人感觉是又爱又恨,没有深入使用之前总觉得这个东西应该很简单,很好用,但是真正使用PopupWindow实现一些效果的时候总会遇到一些问题,但是即便是人家的api有问题, ...

  4. 仿QQ空间根据位置弹出PopupWindow显示更多操作效果

    我们打开QQ空间的时候有个箭头按钮点击之后弹出PopupWindow会根据位置的变化显示在箭头的上方还是下方,比普通的PopupWindow弹在屏幕中间显示好看的多. 先看QQ空间效果图:       ...

  5. 自定义PopupWindow

    PopupWindow,一个弹出窗口控件,可以用来显示任意View,而且会浮动在当前activity的顶部 自定义PopupWindow. 1.extends PopupWindow 2.构造方法中可 ...

  6. PopupWindow 使用

    昨天马失前蹄,为了做一个小键盘,耽误了两个小时,记录一下心路历程 1.关于需求与选择 需求: 点击一个按钮,弹出一个小键盘(类似于输入法键盘) 选择: (1)方案一:KeyboardView 这是百度 ...

  7. popupwindow的基本使用以及基本动画效果

    1.创建一个popupwindow view的布局文件自己写一个就好了,这里就不说了 View view= LayoutInflater.from(context).inflate(R.layout. ...

  8. Android -- PopupWindow(其中嵌套ListView 可以被点击)

    1. 效果图

  9. Android开发学习之路-PopupWindow和仿QQ左滑删除

    这周作业,要做一个类似QQ的左滑删除效果的ListView,因为不想给每个item都放一个按钮,所以决定用PopupWindow,这里记录一下 先放一下效果图: 先说明一下这里面的问题: ①没有做到像 ...

  10. android标题栏上面弹出提示框(二) PopupWindow实现,带动画效果

    需求:上次用TextView写了一个从标题栏下面弹出的提示框.android标题栏下面弹出提示框(一) TextView实现,带动画效果,  总在找事情做的产品经理又提出了奇葩的需求.之前在通知栏显示 ...

随机推荐

  1. UVALive 2035 The Monocycle(BFS状态处理+优先队列)

    这道题目真是非常坎坷啊,WA了很多次,但所有的思路都是奔着广搜去想的,一开始出现了比答案大的数据,才想到了应该是优先队列,再说加上也肯定不会错.一开始我读错了题意,以为旋转并且前行需要的时间跟其他一样 ...

  2. HDU 1681 Frobenius(完全背包+标记装满)

    一个完全背包,数组两百万,暴力可过 #include<iostream> #include<cstdio> #include<cstring> using name ...

  3. Python基础学习2---模块

    模块 你已经学习了如何在你的程序中定义一次函数而重用代码.如果你想要在其他程序中重用很多函数,那么你该如何编写程序呢?你可能已经猜到了,答案是使用模块.模块基本上就是一个包含了所有你定义的函数和变量的 ...

  4. struts2+ajax实现异步验证实现

    由于老师布置作业的需要,在添加管理员的时候,要实现验证添加的管理员的用户名是否在数据库中已经存在,然后再客户端给用户一个提示.我首先想到的就是利用ajax实现异步验证技术,由于利用的ssh框架,所以在 ...

  5. java项目中使用guava的工具包的心得

    原文:http://www.   zuidaima.com/blog/3182745969511424.htm 以前只是听过这个工具包,但是真正用的话还是在D75需求中.我要实现把前台传入的list集 ...

  6. zencart url特殊字符处理

    1. 支持 在后台的seo url 将Outputw3c 改为false 2.删除特殊字符 这对于在少量的zen cart网站上处理少量的特殊字符可能还适用,实际上我们经常在导入产品数据时或者或少会带 ...

  7. PHP递归算法的一个实例 帮助理解

    递归函数为自调用函数,在函数体内直接或间接自己调用自己,但需要设置自调用的条件,若满足条件,则调用函数本身,若不满足则终止本函数的自调用,然后把目前流程的主控权交回给上一层函数来执行,可能这样给大家讲 ...

  8. 业务零影响!如何在Online环境中巧用MySQL传统复制技术【转】

    业务零影响!如何在Online环境中巧用MySQL传统复制技术 这篇文章我并不会介绍如何部署一个MySQL复制环境或keepalived+双主环境,因为此类安装搭建的文章已经很多,大家也很熟悉.在这篇 ...

  9. BASE64-客户端(js)加码-服务器端(c#)解码,URL传递“汉字参数”解决方法

    HttpUtility.UrlEncode 在 Encode 的时候, 将空格转换成加号('+'), 在 Decode 的时候将加号转为空格, 但是浏览器是不能理解加号为空格的, 所以如果文件名包含了 ...

  10. HDU 2188 悼念512汶川大地震遇难同胞——选拔志愿者(基础巴什博奕)

    最最最基础巴什博奕 #include<stdio.h> #include<iostream> #include<cstring> #include<cmath ...