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. xhprof安装&amp;&amp;使用

    听同事说起过一个php性能分析扩展,叫xhprof,近期了解了下. XHProf 是一个轻量级的分层性能測量分析器. 在数据收集阶段.它跟踪调用次数与測量数据,展示程序动态调用的弧线图. 它在报告.后 ...

  2. hdoj--2120--Ice_cream's world I(并查集判断环)

    Ice_cream's world I Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  3. excel如何将一列按奇偶数分成两列

    借助于函数.上图说明一切: 方法一.OFFSET函数, 奇数列公式:C1=OFFSET($A$1,ROW()*2-2,), 偶数列公式:D1=OFFSET($A$1,ROW()*2-1,) 一起下拉即 ...

  4. Oracle 11G R2 用exp无法导出空表解决方法

    四.  Oracle 10g以后增加了expdp和impdp工具,用此工具也可以导出空的表 oracleexpdp/impdp 用法详解 1)  创建逻辑目录,该命令不会在操作系统创建真正的目录,最好 ...

  5. java生成6位随机数的5种方法

    转自:https://blog.csdn.net/u012491783/article/details/76862526/

  6. MVC bundle配置文件模板

    bundle文件放在应用根目录,命名为  bundle.config 内容模板 <?xml version="1.0" encoding="utf-8"? ...

  7. Axure设计软件下载安装及注册

    如图:本地计算机安装了两个版本的Axure,但8版的有问题,点击保存软件就退出了:7版本要想使用的注册授权 https://blog.csdn.net/botree_chan/article/deta ...

  8. 洛谷P3356 火星探险问题(费用流)

    题目描述 火星探险队的登陆舱将在火星表面着陆,登陆舱内有多部障碍物探测车.登陆舱着陆后,探测车将离开登陆舱向先期到达的传送器方向移动.探测车在移动中还必须采集岩石标本.每一块岩石标本由最先遇到它的探测 ...

  9. 小数据量csv文件数据导入数据库(思路)

    大致写写思路,因为sqlserver提供了可以直接导入的图形界面. 1.private static string GetConnectionString(string folderPath)  // ...

  10. addEventListener()与removeEventListener(),追加事件和删除追加事件

    addEventListener()与removeEventListener()用于追加事件和删除追加.所有的DOM节点中都包含这两种方法,并且它们都接受3个参数:要处理的事件名.作为事件处理程序的函 ...