Popupwindow 显示, 其它背景变暗。 并加上点击事件 ~ (用于记录)
public class MainActivity extends Activity implements OnClickListener {
protected int mScreenWidth;
protected int mScreenHeight;
private PopupWindow popupwindow;
private Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(this);
//获取当前屏幕宽高
DisplayMetrics metric = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metric);
mScreenWidth = metric.widthPixels;
mScreenHeight = metric.heightPixels;
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button1:
if (popupwindow != null&&popupwindow.isShowing()) {
popupwindow.dismiss();
return;
} else {
initmPopupWindowView();
popupwindow.showAsDropDown(v, 0, 5);
}
break;
default:
break;
}
}
public void initmPopupWindowView() {
// 获取自己定义布局文件pop.xml的视图
View customView = getLayoutInflater().inflate(R.layout.popview_item,
null, false);
// 创建PopupWindow实例,是宽度和高度
popupwindow = new PopupWindow(customView , mScreenWidth , 600);
popupwindow.setAnimationStyle(R.style.AnimationFade);
WindowManager.LayoutParams params= getWindow().getAttributes();
params.alpha=0.5f;
getWindow().setAttributes(params);
popupwindow.setOutsideTouchable(true);
popupwindow.setFocusable(true);
popupwindow.setTouchable(true);
// popupwindow.setBackgroundDrawable(new BitmapDrawable());
// 自己定义view加入触摸事件
customView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
closePopupWindow();
System.out.println("44444444444444444444");
return false;
}
});
/** 在这里能够实现自己定义视图的功能 */
Button btton2 = (Button) customView.findViewById(R.id.button2);
Button btton3 = (Button) customView.findViewById(R.id.button3);
btton2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent2 = new Intent(MainActivity.this,A.class);
startActivity(intent2);
popupwindow.dismiss();
}
});
btton3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent3 = new Intent(MainActivity.this,B.class);
startActivity(intent3);
popupwindow.dismiss();
}
});
}
/**
* 关闭窗体
*/
private void closePopupWindow()
{
if (popupwindow != null && popupwindow.isShowing()) {
popupwindow.dismiss();
popupwindow = null;
WindowManager.LayoutParams params= getWindow().getAttributes();
params.alpha=1.0f;
getWindow().setAttributes(params);
}
}
}
图1:
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">
图2:
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">
布局文件: activity_mian.xml
<LinearLayout
android:id="@+id/a_c"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#C0C0C0"
>
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:gravity="center"
android:text="点击下拉列表" />
</LinearLayout>
还有一个xml里 。就两个button , 没什么好贴的。
http://download.csdn.net/detail/u012062810/8897455 下载地址
点击popwindow 的时候, ”点击下拉表“ (如图1) 也会变暗。
有解决此方法的小伙伴,希望略微指点下~ 多谢。
Popupwindow 显示, 其它背景变暗。 并加上点击事件 ~ (用于记录)的更多相关文章
- 弹出PopupWindow背景变暗的实现
弹出PopuoWindow后 代码里设置的是PopupWindow默认获取焦点 所以PopupWindow显示的时候其它控件点击是没有反应的 用到的方法是 pwMyPopWindow.setFocus ...
- 仿QQ空间根据位置弹出PopupWindow显示更多操作效果
我们打开QQ空间的时候有个箭头按钮点击之后弹出PopupWindow会根据位置的变化显示在箭头的上方还是下方,比普通的PopupWindow弹在屏幕中间显示好看的多. 先看QQ空间效果图: ...
- js弹窗 js弹出DIV,并使整个页面背景变暗
1.首先写一个遮罩层div,然后再写一个弹窗的div <!-- 遮罩层 --> <div id="cover" style="background: # ...
- j-query应用---鼠标悬停不同文字显示不同背景图片banner动画
源代码部分:注意事项:样式表的引用的路径要一致. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ...
- Android根据Button状态(normal,focused,pressed)显示不同背景图片
Android根据Button状态(normal,focused,pressed)显示不同背景图片 Android中Button 有focused, selected, pressed 等不同状态,通 ...
- VUE2.0 饿了吗视频学习笔记(六):定位问题、文字显示、模糊背景图片、点击事件
一.定位问题按照视频写代码时,发现元素“5个“”定位不对,如下图 正常位置为 还以为是哪里写错了,仔细研究了下,需要在父div上加relative. position:relative/absolut ...
- Android PopupWindow显示位置设置
当点击某个按钮并弹出PopupWindow时,PopupWindow左下角默认与按钮对齐,但是如果PopupWindow是下图的那样,会发 生错位的情况,尤其是不同尺寸的平板上,那错位错的不是一般的不 ...
- 简单 JS 弹出层 背景变暗
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- UIView点击事件。弹出视图,背景虚化。
@interface CountryViewController //背景 @property (strong, nonatomic) UIView *BackView; end //设置背景虚化 - ...
随机推荐
- java 顺序 读写 Properties 配置文件 支持中文 不乱码
java 顺序 读写 Properties 配置文件 ,java默认提供的Properties API 继承hashmap ,不是顺序读写的. 特从网上查资料,顺序读写的代码,如下, import j ...
- Migrations有两个文件迁移数据的方法
不分开迁移报错如下; 解决方案 1 迁移Migration/nfoManage EntityFramework\Enable-Migrations -ContextTypeName InfoModel ...
- SQLserver中用convert函数转换日期格式(2)
), ): :57AM ), ): ), ): ), ): ), ): ), ): ), ): ), ): , ), ): :: ), ): :::827AM ), ): ), ): ), ): ), ...
- rel= "noopener"
rel= "noopener" <a href= "https://www.xiaogezi.cn/" target= "_blank" ...
- 一.Windows I/O模型之选择(select)模型
1.选择(select)模型:选择模型:通过一个fd_set集合管理套接字,在满足套接字需求后,通知套接字.让套接字进行工作.避免套接字进入阻塞模式,进行无谓的等待.选择模型的核心的FD_SET集合和 ...
- UIView 绘制渲染机制
#前言 APP页面优化对小编来说一直是难题,最近一直在不断的学习和总结 ,发现APP页面优化说到底离不开view的绘制和渲染机制.网上有很多精彩的博客,小编借鉴之前N多大牛研究成果,同时结合自己遇到的 ...
- ZBrush软件特性之Edit
ZBrush®中的Edit调控板控制撤销和重做命令,它有一或两个命令设置将根据Tool工具调控板当前选择的工具而定,默认配置的命令仅有文档编辑,不过当激活一个3D工具,只针对这个工具的两个按钮设置变成 ...
- 第九章 Python之面向对象
面向对象编程 面向对象编程是一种程序设计思想,它把对象作为程序的基本单元,一个对象包含了数据和操作数据的函数 面向过程的程序设计把计算机程序视为一系列命令的集合,即一组函数的顺序执行.为了简化程序设计 ...
- 使用node+mysql进行后端开发
使用koa: koa2是一个类,所以引入koa后,要创建实例化“对象”,才能使用koa内部封装的方法. 设置监听端口: 处理http请求: 1.http请求处理链 A.通过app.use()注册asy ...
- EasyUI——DataGrid的自定义单元格点击事件
1.当点击的单元格需要传递参数,并且传递的是row的值时,需要进行转义 function initCompareTable(){ $("#deviceCompareTable"). ...