package com.example.test1;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

////////////////////////////
import android.app.Activity;
import android.graphics.drawable.BitmapDrawable;
//import android.os.Bundle;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
//import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.PopupWindow;

import android.widget.Toast;
////////////////////////////

public class PopupWindow2 extends ActionBarActivity {
   
    ////////////////////////////
     private Button button;
     private Button button1;
     private Button button2;
     private Button button3;
     private Button button4;
     private View popupWindowView;
     private PopupWindow popupWindow;
     private LayoutInflater inflater;
    ////////////////////////////
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_popup_window2);
  
        ////////////////////////////
  button=(Button) findViewById(R.id.button_m);    
  button.setOnClickListener(new ButtonOnClickListener());
        ////////////////////////////
 }
 
 
 
 ////////////////////////////
  private class ButtonOnClickListener implements OnClickListener{
         public void onClick(View v) {
             inflater=(LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
             popupWindowView=inflater.inflate(R.layout.activity_popup_window_sub, null);
          
             popupWindow=new PopupWindow(popupWindowView, LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT,true);
             //必须要有这句否则弹出popupWindow后监听不到Back键
             popupWindow.setBackgroundDrawable(new BitmapDrawable());
             popupWindow.showAtLocation(findViewById(R.id.button_m), Gravity.NO_GRAVITY, 0, 0);
             //让popupWindow获得焦点
             popupWindow.setFocusable(true);
             //设置动画
             //popupWindow.setAnimationStyle(R.style.popupWindowAnimation);
             popupWindow.update();
                          
             //popupWindow中按钮的处理
             button1=(Button) popupWindowView.findViewById(R.id.button1);
             button2=(Button) popupWindowView.findViewById(R.id.button2);
             button3=(Button) popupWindowView.findViewById(R.id.button3);
             button4=(Button) popupWindowView.findViewById(R.id.button4);
             button1.setOnClickListener(new ButtonsOnClickListener());
             button2.setOnClickListener(new ButtonsOnClickListener());
             button3.setOnClickListener(new ButtonsOnClickListener());
             button4.setOnClickListener(new ButtonsOnClickListener());
              
         }
          
     }
      
     private class ButtonsOnClickListener implements OnClickListener {
         public void onClick(View v) {
             switch (v.getId()) {
             case R.id.button1:
                 //System.out.println("点击了按钮1");
              Toast.makeText(getApplicationContext(), "提示:点击了按钮1,点击窗口外部关闭窗口!",
                 Toast.LENGTH_SHORT).show();
                 break;
             case R.id.button2:
                  System.out.println("点击了按钮2");
                 break;
             case R.id.button3:
                  System.out.println("点击了按钮3");
                 break;
             case R.id.button4:
                  //System.out.println("点击了按钮4");
              popupWindow.dismiss(); // 关闭窗口
                 break;
  
             default:
                 break;
             }
  
         }
  
     }
      
     //监听Back事件
     @Override
     public boolean onKeyDown(int keyCode, KeyEvent event) {
         if (keyCode==KeyEvent.KEYCODE_BACK) {
             if (popupWindow!=null&&popupWindow.isShowing()) {
                 popupWindow.dismiss();      
             } else {
                 //MainActivity.this.finish();
              PopupWindow2.this.finish();
             }
         }
         return super.onKeyDown(keyCode, event);
     }

////////////////////////////

@Override
 public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the menu; this adds items to the action bar if it is present.
  getMenuInflater().inflate(R.menu.popup_window2, menu);
  return true;
 }

@Override
 public boolean onOptionsItemSelected(MenuItem item) {
  // Handle action bar item clicks here. The action bar will
  // automatically handle clicks on the Home/Up button, so long
  // as you specify a parent activity in AndroidManifest.xml.
  int id = item.getItemId();
  if (id == R.id.action_settings) {
   return true;
  }
  return super.onOptionsItemSelected(item);
 }
}

//////////////////////////////////////////////////////////////

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.test1.PopupWindow2" >

<Button
            android:id="@+id/button_m"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="30dp"
            android:text="test" />

</RelativeLayout>

//////////////////////////////////////////////////////////////

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.test1.PopupWindow_sub" >
     
    <LinearLayout
        android:id="@+id/linerLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="vertical"
    >
         
        <Button 
            android:id="@+id/button1"
            android:layout_width="200dip"
            android:layout_height="wrap_content"
            android:text="Button1"
            android:textSize="20sp"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="20dip"
        />
         <Button 
            android:id="@+id/button2"
            android:layout_width="200dip"
            android:layout_height="wrap_content"
            android:text="Button2"
            android:textSize="20sp"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="20dip"
        />
          <Button 
            android:id="@+id/button3"
            android:layout_width="200dip"
            android:layout_height="wrap_content"
            android:text="Button3"
            android:textSize="20sp"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="20dip"
        />
           <Button 
            android:id="@+id/button4"
            android:layout_width="200dip"
            android:layout_height="wrap_content"
            android:text="Button4"
            android:textSize="20sp"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="20dip"
        />
         
         
    </LinearLayout>
     
 
</RelativeLayout>

//////////////////////////////////////////////////////////////

20150604_Andriod 窗体PopupWindow的更多相关文章

  1. 20150604_Andriod 窗体PopupWindow动画

    参考地址: http://www.open-open.com/lib/view/open1378720752084.html http://www.jcodecraeer.com/a/anzhuoka ...

  2. Android popupwindow 失去焦点或者点击空白区域时消失的解决方法

    先来看下Android API 的这个Methods: public void setOutsideTouchable (boolean touchable) Controls whether the ...

  3. popUpWindow 动画无法超出窗体的解决方案

    popupWindow 做动画时,当要求有一个放大动画时,动画无法超出窗体,给人的感觉是只有内容在放大,窗体不动. 这是由于窗口大小固定的原因,解决方案是加大popUpwindow的 大小. 一个比较 ...

  4. PopupWindow 防微信弹出右 侧窗体(继承PopupWindow )

    1, pop自定义 public class SelectPicPopupWindow extends PopupWindow { private Button btn_take_photo, btn ...

  5. PopupWindow 从底部弹出窗体

    第一步  : 初始化PopupWindow private void initPop() { if (view == null) { // 照片 view = View.inflate(Registe ...

  6. PopupWindow --- 弹出底部窗体

    第一步 : 布局文件 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:a ...

  7. 仿QQ空间根据位置弹出PopupWindow显示更多操作效果

    我们打开QQ空间的时候有个箭头按钮点击之后弹出PopupWindow会根据位置的变化显示在箭头的上方还是下方,比普通的PopupWindow弹在屏幕中间显示好看的多. 先看QQ空间效果图:       ...

  8. popupwindow的基本使用以及基本动画效果

    1.创建一个popupwindow view的布局文件自己写一个就好了,这里就不说了 View view= LayoutInflater.from(context).inflate(R.layout. ...

  9. webview加载h5,关闭activity时,窗体泄露问题

    问题描述: webview加载一个含有input控件的html页面,当点击input控件是回调app的closepage方法[closepage中只有一个finish操作],出现窗体泄露问题. 分析: ...

随机推荐

  1. 怎么查找执行比较慢的sql语句-DBA给的建议

    1.使用sql动态视图 如下: b.text,a.total_worker_time,a.total_logical_reads,a.total_elapsed_time,execution_coun ...

  2. 一个想了好几天的问题——关于8086cpu自己编写9号中断不能单步的问题

           在<汇编语言>第十五章中我们可能遇到这样的问题:程序运行正确,但是debug单步调试,却无法运行,修改int 9h中断例程入口地址的指令,虚拟模式下,debug提示指令无效, ...

  3. configuring tortoise git and vs code.

    Preparation, SSH keygen: $ git config --global user.name "calos" $ git config --global use ...

  4. Java基础(55):Exception类详解(转)

    Java中的异常 Exception java.lang.Exception类是Java中所有异常的直接或间接父类.即Exception类是所有异常的根类. 比如程序: public class Ex ...

  5. linux第6天 流协议-粘包

    今天学习的主要是对第5天的加强. 比如服务器的多进程,点对点应用聊天程序.父进程子进程互发消息.等等. 流协议-粘包 一般TCP协议会出现粘包,粘包产生的原因一般为.TCP协议是流式传输,不会根据用户 ...

  6. (二)重拾单片机 第一天 LED灯

    由图知道 低电平 亮,高电平 灭 控制第一个 LED1 亮灭程序代码,如下 #include<reg52.h> #define uchar8 unsigned char #define u ...

  7. 事务——sql server中的事务应用举例

    sql中事务只针对一个update,delete,insert语句,如果一段程序中有超过一个这样的语句,就需要每个都判断是否出错,否则就会出现若干我们不希望的情形出现,举例如下(表结构见最后): 1, ...

  8. 夺命雷公狗—angularjs—9—ng-class的自定义函数的用法

    angularjs里面其实给我们留下了一个很不错的地方,他就是可以直接调用函数从而对该位置进行处理, 被点击后展示效果如下所示: 开始走代码吧.... <!doctype html> &l ...

  9. springmvc下上传文件

    使用ajax+表单+jQuery: function sendFile() { var action = "c/goFile.do"; $("#form").a ...

  10. zw版【转发·台湾nvp系列Delphi例程】HALCON AddNoiseWhite

    zw版[转发·台湾nvp系列Delphi例程]HALCON AddNoiseWhite unit Unit1;interfaceuses Windows, Messages, SysUtils, Va ...