正确使用PopupWindow的方法。可以在外面点击消失Pop

LayoutInflater inflater = LayoutInflater.from(EighteenBigActivity.this);
			View view = inflater.inflate(R.layout.font_layout, null);
			
			Button bt1 = (Button) view.findViewById(R.id.small_font);
			Button bt2 = (Button) view.findViewById(R.id.middle_font);
			bt1.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					tag_count = 1;
					System.out.println("数据变更后是: " + tag_count );
					
				}
			});
			bt2.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {

					tag_count = 2;
					System.out.println("数据变更后是: " + tag_count );
				}
			});
			
			pop = new PopupWindow(view, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);
			pop.setContentView(view);
			pop.setWidth(100);
			pop.setHeight(50);
			pop.setOutsideTouchable(true);
			pop.setFocusable(true);
			//让pop可以点击外面消失掉
			pop.setBackgroundDrawable(new ColorDrawable(0));
			
			pop.showAsDropDown(findViewById(R.id.font), 0, 0);
			pop.setOnDismissListener(new OnDismissListener() {
				
				@Override
				public void onDismiss() {
					pop.dismiss();
				}
			});
			
			pop.setTouchInterceptor(new OnTouchListener() {
				
				@Override
				public boolean onTouch(View v, MotionEvent event) {
					if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
						pop.dismiss();
						return true;
					}
					return false;
				}
			});

你可能感兴趣的:(正确使用PopupWindow的方法。可以在外面点击消失Pop)