PopupWindow的基本使用
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的基本使用的更多相关文章
- Android PopupWindow Dialog 关于 is your activity running 崩溃详解
Android PopupWindow Dialog 关于 is your activity running 崩溃详解 [TOC] 起因 对于 PopupWindow Dialog 需要 Activi ...
- Android popupwindow使用心得(一)
最近项目中好多地方用到popupwindow,感觉这个控件还是非常重要的.所以把使用心得总结下,废话不多说,直接上代码. public class MainActivity extends Activ ...
- 不得不吐槽的Android PopupWindow的几个痛点(实现带箭头的上下文菜单遇到的坑)
说到PopupWindow,我个人感觉是又爱又恨,没有深入使用之前总觉得这个东西应该很简单,很好用,但是真正使用PopupWindow实现一些效果的时候总会遇到一些问题,但是即便是人家的api有问题, ...
- 仿QQ空间根据位置弹出PopupWindow显示更多操作效果
我们打开QQ空间的时候有个箭头按钮点击之后弹出PopupWindow会根据位置的变化显示在箭头的上方还是下方,比普通的PopupWindow弹在屏幕中间显示好看的多. 先看QQ空间效果图: ...
- 自定义PopupWindow
PopupWindow,一个弹出窗口控件,可以用来显示任意View,而且会浮动在当前activity的顶部 自定义PopupWindow. 1.extends PopupWindow 2.构造方法中可 ...
- PopupWindow 使用
昨天马失前蹄,为了做一个小键盘,耽误了两个小时,记录一下心路历程 1.关于需求与选择 需求: 点击一个按钮,弹出一个小键盘(类似于输入法键盘) 选择: (1)方案一:KeyboardView 这是百度 ...
- popupwindow的基本使用以及基本动画效果
1.创建一个popupwindow view的布局文件自己写一个就好了,这里就不说了 View view= LayoutInflater.from(context).inflate(R.layout. ...
- Android -- PopupWindow(其中嵌套ListView 可以被点击)
1. 效果图
- Android开发学习之路-PopupWindow和仿QQ左滑删除
这周作业,要做一个类似QQ的左滑删除效果的ListView,因为不想给每个item都放一个按钮,所以决定用PopupWindow,这里记录一下 先放一下效果图: 先说明一下这里面的问题: ①没有做到像 ...
- android标题栏上面弹出提示框(二) PopupWindow实现,带动画效果
需求:上次用TextView写了一个从标题栏下面弹出的提示框.android标题栏下面弹出提示框(一) TextView实现,带动画效果, 总在找事情做的产品经理又提出了奇葩的需求.之前在通知栏显示 ...
随机推荐
- GetClientRect
这个函数好像就是对应于视口的,获取视口的宽高 #include <windows.h> LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPAR ...
- Git学习 -- 自定义Git
忽略特殊文件 在工作区创建.gitignore文件,编写内容 # Windows: Thumbs.db ehthumbs.db Desktop.ini # Python: 忽略Python编译产生的. ...
- nginx slab内存管理
本来这一篇作为nginx系列的开头是不合适的,不过由于nginx进程框架自己的梳理还没完成,这部分又刚好整理完了,就从这开始吧.这儿谈的是nginx的slab的内存管理方式,这种方式的内存管理在ngi ...
- Apache 实现ProxyPass转发URL到Tomcat并实现http自动转https【转载】
转自 Apache 实现ProxyPass转发URL到Tomcat并实现http自动转https - OPEN 开发经验库http://www.open-open.com/lib/view/open1 ...
- string 与wstring 的转换
std::wstring StringToWString(const std::string &str) { std::wstring wstr(str.length(),L' '); std ...
- C#入门经典(3-窗体应用程序-第二章要点)
新建一个窗体用用程序,拖一个按钮,加事件和Text属性.打开Form1Designer.cs.
- zf-关于更改账号密码的问题
一般项目的数据库里都会有一个 SYS_USER表 里面有账号密码 一般 202……70 的都是123加密后的字符串 如果碰到项目运行之后不知道登陆密码的时候 可以在数据库中 把USER_PASS 改成 ...
- 解开神秘面纱之“AngualrJS 中指令相关的嵌入作用域和模板作用域”
原文:https://www.airpair.com/angularjs/posts/transclusion-template-scope-in-angular-directives#r1 原标题: ...
- android脚步---使用framelayout实现霓虹灯效果
轮换帧布局中7个TextView的背景颜色,会出现上面颜色渐变不断变换. 首先在main.xml文件中进行布局 总体布局为framelayout 中间有7个Textview,代表7种不同的颜色,可以看 ...
- keyCode码集合
keycode 8 = BackSpace BackSpace keycode 9 = Tab Tab keycode 12 = Clear keycode 13 = Enter keycode 16 ...