标签:android style blog color io ar for div sp
在一个已出现的poupwindow中,点击页面上的某个按钮,页面将进行跳转到另一个Activity中。popupwindow代码如下:
1 package com.cn.gordon.exhibition.walk.popup; 2 3 import com.cn.gordon.exhibition.walk.activity.ForumArrangementActivity; 4 import com.cn.gordon.exhibition.walk.activity.R; 5 import com.cn.gordon.exhibition.walk.activity.VisitPlanActivity; 6 7 import android.app.Activity; 8 import android.content.Context; 9 import android.content.Intent; 10 import android.graphics.drawable.ColorDrawable; 11 import android.view.LayoutInflater; 12 import android.view.View; 13 import android.view.View.OnClickListener; 14 import android.widget.LinearLayout; 15 import android.widget.PopupWindow; 16 import android.widget.RelativeLayout.LayoutParams; 17 18 public class ArrangementPopupWindow extends PopupWindow { 19 private View contentView; 20 public ArrangementPopupWindow(final Activity context){ 21 LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 22 contentView = inflater.inflate(R.layout.popupwindow_arrangement, null); 23 //int h = context.getWindowManager().getDefaultDisplay().getHeight(); 24 int w = context.getWindowManager().getDefaultDisplay().getWidth(); 25 // 设置SelectPicPopupWindow的View 26 this.setContentView(contentView); 27 // 设置SelectPicPopupWindow弹出窗体的宽 28 this.setWidth(w / 2 + 50); 29 // 设置SelectPicPopupWindow弹出窗体的高 30 this.setHeight(LayoutParams.WRAP_CONTENT); 31 // 设置SelectPicPopupWindow弹出窗体可点击 32 this.setFocusable(true); 33 this.setOutsideTouchable(true); 34 // 刷新状态 35 this.update(); 36 // 实例化一个ColorDrawable颜色为半透明 37 ColorDrawable dw = new ColorDrawable(0000000000); 38 // 点back键和其他地方使其消失,设置了这个才能触发OnDismisslistener ,设置其他控件变化等操作 39 this.setBackgroundDrawable(dw); 40 // mPopupWindow.setAnimationStyle(android.R.style.Animation_Dialog); 41 // 设置SelectPicPopupWindow弹出窗体动画效果 42 //this.setAnimationStyle(R.style.AnimationPreview); 43 LinearLayout layout_forum = (LinearLayout) contentView 44 .findViewById(R.id.layout_forum); 45 LinearLayout layout_visitplan = (LinearLayout) contentView 46 .findViewById(R.id.layout_visitplanarrangement); 47 48 layout_forum.setOnClickListener(new OnClickListener() { 49 50 @Override 51 public void onClick(View v) { 52 if (context.getClass().equals(VisitPlanActivity.class)) { 53 Intent in = new Intent(context,ForumArrangementActivity.class); 54 context.startActivity(in); 55 56 } 57 ArrangementPopupWindow.this.dismiss(); 58 } 59 }); 60 61 62 layout_visitplan.setOnClickListener(new OnClickListener() { 63 64 @Override 65 public void onClick(View v) { 66 if (context.getClass().equals(ForumArrangementActivity.class)) { 67 Intent in = new Intent(context,VisitPlanActivity.class); 68 context.startActivity(in); 69 } 70 71 ArrangementPopupWindow.this.dismiss(); 72 } 73 }); 74 75 } 76 77 public void showPopupWindow(View parent) { 78 if (!this.isShowing()) { 79 // 以下拉方式显示popupwindow 80 this.showAsDropDown(parent, parent.getLayoutParams().width / 2, 18); 81 } else { 82 this.dismiss(); 83 } 84 } 85 }
在popupwindow中需要用到上一个页面传递过来的context,通过context来调用startActivity实现页面的跳转。
标签:android style blog color io ar for div sp
原文地址:http://www.cnblogs.com/SeawinLong/p/3986329.html