Wednesday, September 17, 2014

Android PopupWindow 전체화면


package com.example.popupwindowsample2;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.PopupWindow;

public class MainActivity extends Activity implements OnClickListener {
 private static final String TAG="MainActivity";
 private Button mBtnPopup;
 private MotionPopupWindow mMotionPopupWindow;
 private PopupWindow mPopupWindow;
 private int mTop;

 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  mBtnPopup = (Button) findViewById(R.id.btnPopup);
  mBtnPopup.setOnClickListener(this);
 }

 private void initPopupWindow() {
  if(mPopupWindow == null) {
   final LayoutInflater inflater = (LayoutInflater) MainActivity.this
     .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
   final View popupView = inflater.inflate(R.layout.notice, null, false);
   final Display display = getWindowManager().getDefaultDisplay();
   final int top = getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();
   final int width = display.getWidth();
   final int height = display.getHeight() - top;

   mTop = top;
   mPopupWindow = new PopupWindow(popupView, width, height, true);  
  }
 }

 @Override
 public void onClick(View v) {
  //Display display = ((WindowManager)getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
  initPopupWindow();
  mPopupWindow.showAtLocation(findViewById(R.id.main), Gravity.BOTTOM, mTop, 0);
 }
}

No comments:

Post a Comment