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. unity3d教程运行物理机制

    首先,我们将把Hooke定律写Euler方法结合在一起找到新坐标.加速和速度. Hooke定律是F=kx,这里的F是指由水流产生的力(记住,我们将把水体表面模拟为水流),k是指水流的常量.x则是位移. ...

  2. caioj1497&&bzoj3125: CITY

    震惊!bzoj居然又被苏大佬D飞了... 这题煞笔模板题好吧. 然而bzojAC caiojWA%40??? 好强啊 今天早上发现是m打成n了囧 #include<cstdio> #inc ...

  3. HTTP Error 500.19

    HTTP Error 500.19 - Internal Server Error The requested page cannot be accessed because the related ...

  4. 蓝桥杯--算法提高 排列数 (简单dfs)

    算法提高 排列数   时间限制:1.0s   内存限制:256.0MB      问题描述 0.1.2三个数字的全排列有六种,按照字母序排列如下: 012.021.102.120.201.210 输入 ...

  5. 剑指offer——05用两个栈实现队列(Python3)

    思路:(转) 代码: # -*- coding:utf-8 -*-class Solution: stack1 = [] stack2 = [] def push(self, node): self. ...

  6. TCP和UDP的具体区别

    TCP和UDP的最完整的区别 TCP UDP TCP与UDP基本区别: 1.基于连接与无连接 2.TCP要求系统资源较多,UDP较少: 3.UDP程序结构较简单 4.流模式(TCP)与数据报模式(UD ...

  7. Linux中安装redis的phpredis扩展

    下载phpredis扩展 http://pecl.php.net/package/redis wget http://pecl.php.net/get/redis-4.0.2.tgz 需要环境配置文件 ...

  8. week5_notebooke1

    大纲: 01 装饰器进阶 02 函数的有效信息 03 可迭代对象.迭代器 04 生成器 列表生成式 生成器表达式 05 内置函数 06 二分查找 01 装饰器进阶 #多个装饰器装饰同一个函数: ## ...

  9. 阿里云Maven中央仓库配置

    方式一:统一配置 在maven安装目录/conf下的settings.xml 文件里配置mirrors的子节点,添加如下mirror <mirror> <id>alimaven ...

  10. vue 2.x axios 封装的get 和post方法

    import axios from 'axios' import qs from 'qs' export class HttpService { Get(url, data) { return new ...