参考学习后遇到问题:

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

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. [翻译]:SQL死锁-死锁排除

    As we already saw, the reasons why we have blocking issues and deadlocks in the system are pretty mu ...

  2. OGNl和ValueStack的基础和深入分析

    一.OGNL 1)什么是OGNL? 解析:OGNL是Object Graph Navigation Language(对象图导航语言)它是强大的表达式语言. 2)用途:通过简单一致的表达式语法来读取和 ...

  3. 玩转Docker之安装篇(二)

    按理说,安装软件最好是按照官方文档进行,但由于国内网络的局限性,使我们不得不搭梯子,但终究太麻烦.鉴于此情况,我推荐方案一,利用某公司的加速站点来安装,而且是傻瓜式的,非常方便. 方案一: 在linu ...

  4. UrlRewrite(URL重写)--ASP.NET中的实现

    概述 今天看了下URL重写的实现,主要看的是MS 的URL Rewrite. URL重写的优点有:更友好的URL,支持老版本的URL URL重写的缺点有:最主要的缺点是性能低下,因为如果要支持无后缀的 ...

  5. 【前端福利】用grunt搭建自动化的web前端开发环境-完整教程

    jQuery在使用grunt,bootstrap在使用grunt,百度UEditor在使用grunt,你没有理由不学.不用! 1. 前言 各位web前端开发人员,如果你现在还不知道grunt或者听说过 ...

  6. Fixed Responsive Nav – 响应式的单页网站导航插件

    Fixed Responsive Nav 是一个响应式的,固定的,触摸友好的单页网站导航插件,响应式导航,流畅的动画滚动.该项目采用渐进增强构建,支持工作在 IE6 及以上版本的浏览器. 你可以给导航 ...

  7. 定时器相关 setTimeout setInterval 函数节流

    这个问题也是在参加百度的前端技术学院中遇到的 任务中需要用js实现动画  导师给的评价中setInterval会导致bug 当时不理解   下面把自己学习的过程分享出来 再次理解单线程   老是说js ...

  8. go语言选择语句 switch case

    根据传入条件的不同,选择语句会执行不同的语句.下面的例子根据传入的整型变量i的不同而打印不同的内容: switch i { case 0: fmt.Printf("0") case ...

  9. Box2D自定义重力

    需要给刚体添加一个自定义的属性:m_customGravity,这样就可以动态的修改每一个刚体自定义的重力,查找box2d源码大约在5486行,加上红色的一句代码 b2Island.prototype ...

  10. 给SHP文件定义投影

    #!/usr/bin/env python # -*- coding: utf-8 -*- import urllib.request import os def get_epsg_code(epsg ...