标签:
public class TeacherInfoActivity extends Activity {
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.teacherinfo_aty);
tv=(TextView) findViewById(R.id.tvw);
tv.setOnClickListener(new OnClickListener(){
@SuppressLint("NewApi") @Override
public void onClick(View v) {
System.out.println("这里执行了");
final RelativeLayout rlt=new RelativeLayout(getApplicationContext());
final TextView tv_fullScreen=new TextView(TeacherInfoActivity.this);
tv_fullScreen.setText("我要把整个屏幕沾满了");
tv_fullScreen.setBackgroundColor(Color.parseColor("#ffff00"));
WindowManager.LayoutParams params=new WindowManager.LayoutParams();
params.height=WindowManager.LayoutParams.MATCH_PARENT;
params.width=WindowManager.LayoutParams.MATCH_PARENT;
params.flags=WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
params.format=PixelFormat.TRANSLUCENT;
params.type=WindowManager.LayoutParams.TYPE_APPLICATION;
final WindowManager wm=(WindowManager) getSystemService(Context.WINDOW_SERVICE);
wm.addView(rlt, params);
RelativeLayout.LayoutParams params_tv_fullscreen= new RelativeLayout.LayoutParams(200,150);
rlt.setGravity(Gravity.CENTER);
rlt.addView(tv_fullScreen,params_tv_fullscreen);
TextView tv_image= new TextView(getApplicationContext());
tv_image.setBackground(getApplicationContext().getResources().getDrawable(R.drawable.ic_launcher));
RelativeLayout.LayoutParams params_tv_image= new RelativeLayout.LayoutParams(100,50);
params_tv_image.setMargins(50, -20, 0, 0);
rlt.addView(tv_image,params_tv_image);
tv_fullScreen.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(TeacherInfoActivity.this, "我被点击了,我要干掉自己!", 0).show();
wm.removeView(rlt);
}
});
}
});
}
}
标签:
原文地址:http://www.cnblogs.com/hanyong/p/4446287.html