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. 模版引擎Handlebars语法(1)

    <script src="handlebars.js"></script></head><body> <div id=&quo ...

  2. java socket网络编程(多线程技术)

    Client.java import java.io.*; import java.net.*; import java.util.*; public class Client { public st ...

  3. HDU 3265 Posters ——(线段树+扫描线)

    第一次做扫描线,然后使我对线段树的理解发生了动摇= =..这个pushup写的有点神奇.代码如下: #include <stdio.h> #include <algorithm> ...

  4. MapReduce常见算法

    1.单词计数 2.数据去重 3.排序 4.Top K(求数据中的最大值) 5.选择 6.投影 7.分组 8.多表连接 9.单表关联

  5. 风格一致的backItem在项目中怎样设置

    在相应的navigationController中重写- (void)pushViewController:(UIViewController *)viewController animated:(B ...

  6. MySQL数据类型:SQL_MODE设置不容忽视

    [IT168 技术]SQL_MODE可能是比较容易让开发人员和DBA忽略的一个变量,默认为空.SQL_MODE的设置其实是比较冒险的一种设置,因为在这种设置下可以允许一些非法操作,比如可以将NULL插 ...

  7. Java去除字符串中的空格

    特别注意了 Strim或者Trip都是只能去除头部和尾部的空字符串.中间的部分是不能够去除的! 推荐使用ApacheCommonse的StringUtils.deleteWhitespace(&quo ...

  8. webapp之路--之ios上图标

    以前我们用过favicon在浏览器给网站进行身份标识,用法如下: <link href="http://image.feeliu.com/web/favicon.ico" r ...

  9. Git 常用命令汇总

    #安装git yum install -y curl-devel expat-devel gettext-devel openssl-devel zlib-devel yum install -y g ...

  10. cookie讲解-------浏览器种cookie

    1  responce添加Set-Cookie参数: http request的返回responce为: [('Content-Type', 'application/x-javascript'), ...