Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //[email protected] Saturday, April 09 2011 01:32 AM
- import android.graphics.*;
- import android.graphics.drawable.BitmapDrawable;
- import android.graphics.drawable.Drawable;
- import android.app.Activity;
- import android.content.*;
- import android.os.Bundle;
- import android.view.*;
- import android.view.View.*;
- import android.widget.*;
- public class yoga1290 extends Activity implements OnClickListener {
- public Button b;
- public void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- LinearLayout fr=new LinearLayout(this);
- fr.setOrientation(LinearLayout.VERTICAL);
- b=new Button(this);
- b.setText("Click Me!");
- b.setOnClickListener(this);
- fr.addView(b);
- setContentView(fr);
- }
- @Override
- public void onClick(View v) {
- b.setText("Click to hide/show!");
- TextView tv = new TextView(this);
- tv.setText("This is a Popup :)");
- new yg(tv,b,200,200);
- }
- }
- class yg extends PopupWindow
- {
- public yg(View v,View mv,int w,int h)
- {
- super(v,w,h,true);
- //TODO Better Background may be,cuz this is empty transparent background
- setBackgroundDrawable(new BitmapDrawable());
- setOutsideTouchable(true);
- setTouchable(true);
- setTouchInterceptor(new OnTouchListener() {
- public boolean onTouch(View v, MotionEvent event) {
- if(event.getAction() == MotionEvent.ACTION_OUTSIDE) {
- setFocusable(false);
- dismiss();
- return true;
- }
- //your code when touched on the event
- return false;
- }
- });
- int loc[]=new int[2];
- mv.getLocationOnScreen(loc);
- showAtLocation(mv,Gravity.NO_GRAVITY, 0, loc[1]+ mv.getMeasuredHeight() );
- }
- }
Add Comment
Please, Sign In to add comment