参考学习后遇到问题:

要引用:有好几个,可以用错误提示解决;

import android.widget.PopupWindow;

import android.widget.Toast;

Activity调用过程 :

首先定义一个BUTTON变量和mContext

private Button mshowBtn;
    private Context mContext;

@Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  startService(new Intent(LoginActivity.this, MicroVideoService.class));
  bindXMPPService();
  setContentView(R.layout.loginpage);
  mContext=this;  
  initView();
 }

//指定事件

mshowBtn= (Button) findViewById(R.id.showbtn);
  mshowBtn.setOnClickListener(mshowBtnOnClickListener);

//实现事件并调用

private OnClickListener mshowBtnOnClickListener= new OnClickListener(){
 @Override
 public void onClick(View v) {
  showPopWindow(mContext,v);
 }
   
    };

(转自:import android.widget.PopupWindow;)

Android 中PopupWindow使用。

PopupWindow会阻塞对话框,要在外部线程 或者 PopupWindow本身做退出才行。

mypopWindow.xml的Layout设计如下

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#259"
    android:orientation="vertical" >
 
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Here is Pop Window" />
 
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="OK" />
 
    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Cancle" />
 
</LinearLayout>
 
MainActivity.java文件。

在MainActivity的Button按钮单击,然后显示PopupWindow。

private void showPopWindow(Context context, View parent)
    {      
        LayoutInflater inflater = (LayoutInflater)             
                context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);    
        final View vPopWindow=inflater.inflate(R.layout.mypopwindow, null, false); 
        //宽300 高300           
        final PopupWindow popWindow = new PopupWindow(vPopWindow,300,300,true);
        Button okButton = (Button)vPopWindow.findViewById(R.id.button1);
        okButton.setOnClickListener(new View.OnClickListener() {
             
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Toast.makeText(MainActivity.this, "You click OK", Toast.LENGTH_SHORT).show();
            }
        });
         
        Button cancleButton = (Button)vPopWindow.findViewById(R.id.button2);
        cancleButton.setOnClickListener(new View.OnClickListener() {
             
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                popWindow.dismiss(); //Close the Pop Window
            }
        });
         
        popWindow.showAtLocation(parent, Gravity.CENTER, 0, 0);
         
         
    }
 
效果图如下:最后显示是剧中的,这里我只是截取了部分图片。
 
单击Ok按钮显示You click OK信息。单击取消,则关闭PopupWindow.

Android 中PopupWindow使用 (转)的更多相关文章

  1. Android中Popupwindow和Dialog的区别

    Android中的对话框有两种:PopupWindow和AlertDialog.它们都可以实现弹窗功能,但是他们之间有一些差别,下面总结了一点. (1)Popupwindow在显示之前一定要设置宽高, ...

  2. Android中PopupWindow用法

    参考资料链接:http://developer.android.com/reference/android/widget/PopupWindow.html 在Android中有很多级别的Window, ...

  3. Android中PopupWindow中有输入框时无法弹出输入法的解决办法

    PopupWindow window=new PopupWindow(view, LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); //必须让p ...

  4. android中使用PopupWindow实现弹出窗口菜单

    结合上篇android中使用ViewPager实现图片拖动,我们实现了点击“帮助”按钮的功能,这一篇则是接着上一篇,让我们一起来完成“我的”按钮的功能,这一功能,则是使用PopupWindow来实现弹 ...

  5. Android中的PopupWindow详解

      Android的对话框有两种:PopupWindow和AlertDialog.它们的不同点在于: AlertDialog的位置固定,而PopupWindow的位置可以随意 AlertDialog是 ...

  6. Android中的自定义控件(一)

    自定义控件是根据自己的需要自己来编写控件.安卓自带的控件有时候无法满足你的需求,这种时候,我们只能去自己去实现适合项目的控件.同时,安卓也允许你去继承已经存在的控件或者实现你自己的控件以便优化界面和创 ...

  7. Android中使用SurfaceView+MediaPlayer+自定义的MediaController实现自定义的视屏播放器

    效果图如下: (PS本来是要给大家穿gif动态图的,无奈太大了,没法上传) 功能实现:暂停,播放,快进,快退,全屏,退出全屏,等基本功能 实现的思路: 在主布局中放置一个SurfaceView,在Su ...

  8. Android 使用PopupWindow实现弹出菜单

    在本文当中,我将会与大家分享一个封装了PopupWindow实现弹出菜单的类,并说明它的实现与使用. 因对界面的需求,android原生的弹出菜单已不能满足我们的需求,自定义菜单成了我们的唯一选择,在 ...

  9. Android中那些有你不知道的事

    在安卓开发中,总有那么一些看似简单,实则绊脚的难题,等你去探索,等你去解决,也许你已经遇见了解决了,也许你还没碰上,写下这篇总结,希望能帮助那行即将遇到的朋友,快速解决这些小问题! 一.activit ...

随机推荐

  1. Bash中的任务(job)管理

    本来不准备写这篇博客的,因为任务管理(job管理)非常非常常用,以至于觉得根本没有必要去写这样一个东西.但想了下,还是记录一下吧,也许有人会用到呢. 不知你是否碰到过这样的情况,当你兴致勃勃的打开VI ...

  2. MySQL配置文件mysql.ini参数详解、MySQL性能优化

    my.ini(Linux系统下是my.cnf),当mysql服务器启动时它会读取这个文件,设置相关的运行环境参数. my.ini分为两块:Client Section和Server Section.  ...

  3. 分布式环境下rabbitmq发布与订阅端

    假设rabbitmq配置了集群,且客户端连接rabbitmq-server通过lvs实现HA但一般情况下不建议做LB.在分布式系统的环境下,由于节点的非预知性,使用spring amqp模板进行配置不 ...

  4. java内存模型-顺序一致性

    数据竞争与顺序一致性保证 当程序未正确同步时,就会存在数据竞争.java 内存模型规范对数据竞争的定义如下: 在一个线程中写一个变量, 在另一个线程读同一个变量, 而且写和读没有通过同步来排序. 当代 ...

  5. jQuery TimeCircles 倒计时

    在线实例 默认 倒计时 使用方法 <h1 style="margin: 40px; font: 32px Microsoft Yahei; text-align: center;&qu ...

  6. 【HTML】字符(Glyphs)收集

    Special Characters " " " quotation mark u+0022 ISOnum p:before { content:"\0022& ...

  7. 关于EJB的理解

    这一段时间一直在北京面试,很多都有关EJB的相关问题,于是上网查了各种资料.所以,EJB到底是什么? 简而言之:EJB就是将已编写的软件中的业务类.不放到客户端软件中,而将其打包放入服务器中.以C/S ...

  8. Android 开源框架Universal-Image-Loader完全解析(三)---源代码解读

    转载请注明本文出自xiaanming的博客(http://blog.csdn.net/xiaanming/article/details/39057201),请尊重他人的辛勤劳动成果,谢谢! 本篇文章 ...

  9. Android 短信验证码平台

    1.容联云通讯 (目前只支持国内.收费) http://www.yuntongxun.com/ 2.bmob (目前只支持国内.收费) http://www.bmob.cn/ 3.阿里大鱼(目前只支持 ...

  10. mac ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib /mysql/mysql.sock' (111)

    之前装了mysql,今天打开mysql的时候报了个Can't connect to local MySQL server through socket '/var/lib /mysql/mysql.s ...