• Android进阶篇PopupWindow的使用


    /**
     * @author gongchaobin
     *
     * 自定义popuwindow
     * @version 2012-12-12
     */
    public class MyPopuWindow {
    	private LayoutInflater mInflater;
    	private PopupWindow mPopupWindow;
    	private View mView;
    	private Button mBtn;
    	
    	/**
    	 * @param context 上下文
    	 * @param resId layout资源ID
    	 * @param width popuwindow的宽
    	 * @param height popuwindw的高
    	 * @param view 显示位置相对的view 
    	 */
    	public MyPopuWindow(Context context,int resId,int width,int height,OnClickListener clickListener,View view){
    		mInflater = LayoutInflater.from(context);
    		mView = mInflater.inflate(resId, null);
    		mPopupWindow = new PopupWindow(mView, width, height);
    		
    		mPopupWindow.setBackgroundDrawable(new BitmapDrawable());
            /*设置触摸外面时消失*/  
    		mPopupWindow.setOutsideTouchable(true);
    //        /*设置系统动画*/  
    //        popupWindow.setAnimationStyle(R.style.PopupAnimation);
    		mPopupWindow.update();
    		mPopupWindow.setTouchable(true);
    	      /*设置点击menu以外其他地方以及返回键退出*/  
    		mPopupWindow.setFocusable(true);
    		mPopupWindow.showAsDropDown(view);
    		
    		mBtn = (Button) mView.findViewById(R.id.button1);
    		mBtn.setOnClickListener(clickListener);
    		
    	     /** 
             * 解决再次点击MENU键无反应问题   
             */
    		mView.setFocusableInTouchMode(true);
    		mView.setOnKeyListener(new OnKeyListener() {  
                public boolean onKey(View v, int keyCode, KeyEvent event) {  
                    // TODO Auto-generated method stub  
                    if ((keyCode == KeyEvent.KEYCODE_MENU)&&(mPopupWindow.isShowing())) { 
                    	mPopupWindow.dismiss();
                        return true;  
                    }else if(event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_BACK){
                    	mPopupWindow.dismiss();
                        return false;
                    }
                    return false;  
                }  
            });
    	}
    }
    

      

  • 相关阅读:
    sql中where和having的区别
    mysql中locate和substring函数使用
    使用jdk进行数据迁移(sqlite迁移mysql)
    mysql数值函数
    mysql字符串函数
    zabbix-2.2.2(Ubuntu 14.04 LTS/OpenLogic 7.2)
    Piwik-2.16.1 (OpenLogic CentOS7.2)
    Nagios-4.1.1 (OpenLogic CentOS 7.2)
    Bugzilla-5.0.3 (OpenLogic CentOS 7.2)
    GitLab-CE-8.9.4 (OpenLogic CentOS 7.2)
  • 原文地址:https://www.cnblogs.com/gongcb/p/2514830.html
Copyright © 2020-2023  润新知