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. bootstrap's plugin:sthe usage of carousel

    if we want use the carousel.js,we need quote it in the page. sample code: <div id="myCarouse ...

  2. w3chtml页面和css书写规范

    http://www.cnblogs.com/Wenwang/archive/2011/09/07/2169881.html

  3. C++中运行外部程序

    关于三个SDK函数: WinExec, ShellExecute,CreateProcess 的其他注意事项: [1]定义头文件 必须定义以下两个头文件: #include <shlobj.h& ...

  4. Chapter 1 First Sight——17

    Once I got around the cafeteria, building three was easy to spot. 我一走出自助餐厅,很容易看见建筑三. A large black & ...

  5. Git 分支-利用分支进行开发的工作流程

    3.4 Git 分支 - 利用分支进行开发的工作流程 利用分支进行开发的工作流程 现在我们已经学会了新建分支和合并分支,可以(或应该)用它来做点什么呢?在本节,我们会介绍一些利用分支进行开发的工作流程 ...

  6. HDFS在Linux下的命令

    1.对hdfs操作的命令格式是 1.1hadoop fs  -ls <path> 表示对hdfs下一级目录的查看 1.2 hadoop fs -lsr <path> 表示对hd ...

  7. php获取文件名

    php获取文件名$phpself =$_SERVER['PHP_SELF']; //获取当前文件名$str = end(explode("/",$phpself)); //去掉'/ ...

  8. apache禁止公网IP访问的配置

    由于最近在配置负载均衡环境 外网使用Nginx做代理,分发到Apache服务器上,所以不希望Apache配置的服务被外网访问,只希望内网Nginx访问,所以只能使用局域网IP访问 配置方法: 打开Ap ...

  9. POJ 2240 Arbitrage Bellman_ford 判读是否存在正环

    和POJ1860差不多,就是用bellmanford判读是否存在正环,注意的是同种货币之间也可以交换,就是说:A货币换A货币汇率是2的情况也是存在的. #include<stdio.h> ...

  10. 转:web_submit_data和web_submit_form的差别

    在LoadRunner中有两个常用函数:Web_submit_form和Web_submit_data,在群里有人问这两个函数有什么区别.为什么会有两个不同却功能相似的函数.区别在哪里. 首先,从工具 ...