package com.et;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
public class TestPopupWindow extends Activity{
private static final String TAG = TestPopupWindow.class.getSimpleName();
private LinearLayout flayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
flayout = new LinearLayout(this);
LinearLayout.LayoutParams lParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);
flayout.setLayoutParams(lParams);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
lp.setMargins(10, 10, 10, 10);
Button btn = new Button(this);
btn.setText("popupWindow");
btn.setLayoutParams(lp);
flayout.addView(btn);
this.addContentView(flayout, lParams);
btn.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
showPopWindow();
}});
Button btC = new Button(this);
btC.setText("cancel");
btC.setLayoutParams(lp);
btC.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
if(pwindow != null){
pwindow.dismiss();
}
}});
flayout.addView(btC);
}
PopupWindow pwindow =null;
private void showPopWindow(){
Log.d(TAG, "///showpopwindow/////");
LayoutInflater infalter = this.getLayoutInflater();
View v = infalter.inflate(R.layout.popmessage,(ViewGroup)this.findViewById(R.id.toast_layout_root));
pwindow = new PopupWindow(v,200,200);
pwindow.setFocusable(true);
pwindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.icon));
pwindow.showAtLocation(flayout , Gravity.CENTER, 0, 0);
}
}