/** * 弹出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之组件4
  2. android组件
  3. 【转】android常用组件
  4. android studio 引入另一个XML文件的布局控件
  5. android 我的功能模块模板布局之一
  6. android经常调用的组件
  7. 解决TabLayout+viewpager 滑动切换时 布局文件不是从头显示
  8. Android四大组件Service之bindService启动

随机推荐

  1. Failed to find provider info for com.e
  2. 如何在Android上使用opencv
  3. Android(安卓)服务端将位置信息发送给客
  4. Android实现城市选择三级联动
  5. Android(安卓)studio使用git教程
  6. Android(java)学习笔记38:Android(安卓)短信
  7. android 游戏 动画
  8. android sdcard的研究
  9. Android(安卓)服务入门(电话监听)
  10. AndroidX RecyclerView总结-测量布局