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. winform显示系统托盘,双击图片图表显示窗体,退出窗体是否提示

    private void Form1_FormClosing(object sender, FormClosingEventArgs e) { DialogResult result = Messag ...

  2. java连接sql server

    package com.cps.rom.utils; /************************************************************************ ...

  3. 石子合并(区间dp)

    石子合并(一) 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描写叙述     有N堆石子排成一排,每堆石子有一定的数量.现要将N堆石子并成为一堆.合并的过程仅仅能每次将相邻 ...

  4. codecombat之边远地区的森林1-11关及地牢38关代码分享

    codecombat中国游戏网址:http://www.codecombat.cn/ 全部代码为javascript代码分享 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ...

  5. poj--3630--Phone List(字典树+前缀判断)

    Phone List Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Submit St ...

  6. WebRTC开源项目一览之二

    .Kurento视频直播系统4.1  应用实例搞视频会议就会涉及一对多.多对多.广播.转码.混音.合屏.录制,这就需要用到流媒体服务器,而kurento就具有这些功能.他主要用来作为webrtc的流媒 ...

  7. 如何在maven项目中使用spring

    今天开始在maven项目下加入spring. 边学习边截图. 在这个过程中我新建了一个hellospring的项目.于是乎从这个项目出发开始研究如何在maven项目中使用spring.鉴于网上的学习资 ...

  8. Linux学习日记——字符处理

    (菜鸡学习日记 各种使用命令只列举了常用几种,发现错误望指正) 一.管道 在Linux 中,管道就是一个固定大小的缓冲区,大小为一页4K.它是一种通信的机制,可以使用管道符“ | ” 来连接进程,连接 ...

  9. ddk安装失败后的处理

    7600.16385.1版本的DDK,在xp的本上死活按不上,怎么办呢?自己就把其他机器上安装的DDK目录,拷贝过来. 怎么建编译环境呢? 查看x86 Checked Build Environmen ...

  10. Oracle 合并查询

    8).合并查询有时在实际应用中,为了合并多个select语句的结果,可以使用集合操作符号union,union all,intersect,minus.多用于数据量比较大的数据局库,运行速度快.1). ...