Skip to content

Instantly share code, notes, and snippets.

Created January 27, 2016 06:48
Show Gist options
  • Save anonymous/2bc5f15228337e49e049 to your computer and use it in GitHub Desktop.
Save anonymous/2bc5f15228337e49e049 to your computer and use it in GitHub Desktop.
public void onWindowFocusChanged(boolean hasFocus) {
int[] location = new int[2];
//Button button = (Button) findViewById(R.id.actionbar_Post_Cover);
ImageView button = (ImageView) findViewById(R.id.actionbar_Post_Cover);
// Get the x, y location and store it in the location[] array
// location[0] = x, location[1] = y.
button.getLocationOnScreen(location);
//Initialize the Point with x, and y positions
p = new Point();
p.x = location[0];
p.y = location[1];
}
// The method that displays the popup.
private void showPopup(final Activity context, Point p) {
int popupWidth = R.attr.actionBarSize;
int popupHeight = 1200;
// Inflate the popup_layout.xml
LinearLayout viewGroup = (LinearLayout) findViewById(R.id.popup);
LayoutInflater layoutInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = layoutInflater.inflate(R.layout.popup_layout, viewGroup);
// Creating the PopupWindow
final PopupWindow popup = new PopupWindow(context);
popup.setContentView(layout);
popup.setWidth(popupWidth);
popup.setHeight(popupHeight);
popup.setFocusable(true);
// Some offset to align the popup a bit to the right, and a bit down, relative to button's position.
int OFFSET_X = 0;
int OFFSET_Y = 145;
// Clear the default translucent background
popup.setBackgroundDrawable(new BitmapDrawable());
// Displaying the popup at the specified location, + offsets.
popup.showAtLocation(layout, Gravity.NO_GRAVITY, p.x + OFFSET_X, p.y + OFFSET_Y);
// Getting a reference to Close button, and close the popup when clicked.
//Button close = (Button) layout.findViewById(R.id.close);
ImageView close = (ImageView) layout.findViewById(R.id.popup_Controls_Controls_NextBtn);
close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
popup.dismiss();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment