Android examples for User Interface:PopupWindow
Inits the PopupWindow.
//package com.java2s; import android.content.Context; import android.graphics.Color; import android.graphics.drawable.ColorDrawable; import android.os.Handler; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.widget.PopupWindow; public class Main { static final int DEFAULT_DELAY = 200; protected static PopupWindow mWindow; protected static Handler mHandler = new Handler(); /**//from www . j ava 2 s . c om * Inits the popup. * * @param c * the c */ protected static void initPopup(Context c, boolean shouldDismissOnOutsideTouch) { mWindow = new PopupWindow(c); mWindow.setBackgroundDrawable(new ColorDrawable(Color.BLACK)); mWindow.getBackground().setAlpha(200); mWindow.setTouchable(true); if (shouldDismissOnOutsideTouch) { mWindow.setOutsideTouchable(true); mWindow.setFocusable(false); mWindow.setTouchInterceptor(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_OUTSIDE) { mHandler.postDelayed(new Runnable() { @Override public void run() { mWindow.dismiss(); } }, DEFAULT_DELAY); return true; } return false; } }); } else { mWindow.setOutsideTouchable(false); mWindow.setFocusable(false); } } }