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 显示, 其它背景变暗。 并加上点击事件 ~ (用于记录)的更多相关文章

  1. 弹出PopupWindow背景变暗的实现

    弹出PopuoWindow后 代码里设置的是PopupWindow默认获取焦点 所以PopupWindow显示的时候其它控件点击是没有反应的 用到的方法是 pwMyPopWindow.setFocus ...

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

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

  3. js弹窗 js弹出DIV,并使整个页面背景变暗

    1.首先写一个遮罩层div,然后再写一个弹窗的div <!-- 遮罩层 --> <div id="cover" style="background: # ...

  4. j-query应用---鼠标悬停不同文字显示不同背景图片banner动画

    源代码部分:注意事项:样式表的引用的路径要一致. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ...

  5. Android根据Button状态(normal,focused,pressed)显示不同背景图片

    Android根据Button状态(normal,focused,pressed)显示不同背景图片 Android中Button 有focused, selected, pressed 等不同状态,通 ...

  6. VUE2.0 饿了吗视频学习笔记(六):定位问题、文字显示、模糊背景图片、点击事件

    一.定位问题按照视频写代码时,发现元素“5个“”定位不对,如下图 正常位置为 还以为是哪里写错了,仔细研究了下,需要在父div上加relative. position:relative/absolut ...

  7. Android PopupWindow显示位置设置

    当点击某个按钮并弹出PopupWindow时,PopupWindow左下角默认与按钮对齐,但是如果PopupWindow是下图的那样,会发 生错位的情况,尤其是不同尺寸的平板上,那错位错的不是一般的不 ...

  8. 简单 JS 弹出层 背景变暗

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  9. UIView点击事件。弹出视图,背景虚化。

    @interface CountryViewController //背景 @property (strong, nonatomic) UIView *BackView; end //设置背景虚化 - ...

随机推荐

  1. 【iOS开发系列】UIDevice设备信息

    [1] 推断是否是横向屏: BOOL b=UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation); 获取设备uniqu ...

  2. UVA 10593 Kites DP

    The season of flying kites is well ahead. So what? Let us make an inventory for kites. We are givena ...

  3. 转:utf8汉字编码16进制对照

    http://blog.chinaunix.net/uid-25544300-id-3281847.html GB    Unicode  UTF-8     Chinese Character Co ...

  4. notepad++ 查找引用(Find Reference)(适用于c c++及各类脚本比如lua、python等)

    在程序开发过程中,程序员经常用到的一个功能就是查找引用(Find Reference),Visual Studio里面的对应功能是“查找所有引用”(Find All References). 我在使用 ...

  5. [jzoj 3175] 数树数 解题报告 (树链剖分)

    interlinkage: https://jzoj.net/senior/#main/show/3175 description: 给定一棵N 个节点的树,标号从1~N.每个点有一个权值.要求维护两 ...

  6. Swagger中添加Token验证

    1.该连接链接到api中基本的swagge功能:http://www.cnblogs.com/hhhh2010/p/5234016.html 2.在swagger中使用验证(这里使用密码验证模式)ht ...

  7. node.js连接数据库登录注册,修改用户(页面的ajax请求)

    首先给大家看一下目录结构,结构如下: index.html 首页(显示所有的用户信息) login.html 登录页 register.html 注册页 db.js 配置链接数据库参数 dbhelpe ...

  8. 列表查询组件代码, 简化拼接条件SQL语句的麻烦

    列表查询组件代码, 简化拼接条件SQL语句的麻烦 多条件查询

  9. Win10 UI入门 导航滑动条 求UWP工作

    借鉴了 段博琼 大哥写的导航滑动,自己实现了一个类似安卓 IOS 导航滑动条 支持等比例 分割 tabView 支持动画滑动 效果如下图 WYGrid 你可以想象一个GridView  itemsWr ...

  10. C++中关于文本内容的实用操作集合(新)(添加一些关于文件流的介绍)

    首先先给大家一个链接:http://baike.baidu.com/view/1679747.htm 主要是关于ios的使用,头文件要include<ios>,然后就可以调用下面的一些操作 ...