/** * 弹出PopupWindow */public void initPopupWindow() {// 加载PopupWindow的布局文件LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);View view = layoutInflater.inflate(R.layout.popup, null);// 加载PopupWindow的媒介布局文件View parentView = layoutInflater.inflate(R.layout.first, null);// 实例化PopupWindow中的组件// TextView titleTextView = (TextView)// view.findViewById(R.id.popup_title);// ImageView editImg = (ImageView) view.findViewById(R.id.popup_edit);// ImageView listenImg = (ImageView)// view.findViewById(R.id.popup_listen);// SeekBar seekBar = (SeekBar) view.findViewById(R.id.popup_progress);// TextView progressTextView = (TextView) view// .findViewById(R.id.popup_progress_tv);// view.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,// LayoutParams.WRAP_CONTENT));TextView black=(TextView)view.findViewById(R.id.black_txt);black.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubif (popupWindow != null) {popupWindow.dismiss();}}});GridView gridView = (GridView) view.findViewById(R.id.popup_grid);GridViewAdapter adapter = new GridViewAdapter(this, mPictures, mTitles);gridView.setAdapter(adapter);gridView.setOnItemClickListener(new ItemClickListener());gridView.setOnItemSelectedListener(new OnItemSelectedListener() {/* * (non-Javadoc) *  * @see * android.widget.AdapterView.OnItemSelectedListener#onItemSelected * (android.widget.AdapterView, android.view.View, int, long) */@Overridepublic void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3) {// TODO Auto-generated method stub}/* * (non-Javadoc) *  * @see * android.widget.AdapterView.OnItemSelectedListener#onNothingSelected * (android.widget.AdapterView) */@Overridepublic void onNothingSelected(AdapterView<?> arg0) {// TODO Auto-generated method stub}});// 声明并实例化PopupWindowpopupWindow = new PopupWindow(view, LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);// 为PopupWindow设置弹出的位置// popupWindow.showAsDropDown(parentView);// popupWindow.setBackgroundDrawable(new BitmapDrawable());popupWindow.setFocusable(true);popupWindow.setTouchable(true);// popupWindow.// popupWindow.update();// popupWindow.setBackgroundDrawable(new BitmapDrawable());popupWindow.setOutsideTouchable(true);// 点击窗口外消失,需要设置背景、焦点、touchable、update// popupWindow.setpopupWindow.setWindowLayoutMode(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);popupWindow.showAtLocation(parentView, Gravity.NO_GRAVITY, 0, 0);// popupWindow.setFocusable(true);// 这句是为了防止弹出菜单获取焦点之后,点击activity的其他组件没有响应// popupWindow.setAnimationStyle(R.style.popup_show_out);popupWindow.setAnimationStyle(android.R.style.Animation_Translucent);popupWindow.getContentView().findViewById(R.id.main).setOnKeyListener(new OnKeyListener() {@Overridepublic boolean onKey(View v, int keyCode, KeyEvent event) {// TODO Auto-generated method stubLog.i("lxm", "key press");switch (event.getAction()) {case KeyEvent.ACTION_DOWN:if (keyCode == KeyEvent.KEYCODE_MENU|| keyCode == KeyEvent.KEYCODE_BACK) {if (popupWindow != null) {popupWindow.dismiss();}}break;}return false;}});}

更多相关文章

  1. Android(安卓)调用WCF实例详解
  2. 【android】recycleview小整理
  3. Android中如何查看内存(下)
  4. 【转】android常用组件
  5. Android(安卓)笔记.代码段
  6. android组件
  7. android之组件4
  8. android 多媒体部分学习笔记十--简单视频播放
  9. android之【LinearLayout自定义View】

随机推荐

  1. 在cmd窗口中查询android的sqlite3数据库
  2. Android中Fragment嵌套Fragment,切换Fragm
  3. 【Android(安卓)Developers Training】 7
  4. Android内存溢出的解决方法(VMRuntime.get
  5. Android四种模式里隐含的哲学
  6. ubuntu 下android 真机调试配置
  7. Android(安卓)DataBinding完全解析
  8. Android(安卓)gradle SourceSets介绍与使
  9. android网易跟帖盖楼布局
  10. 安卓 activity的四种启动模式