public class Mouse extends Activity{
private WindowManager mWM;
private ImageView ivCursor;
private WindowManager.LayoutParams mParams;
private int a,b;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
}
public void mouse(){
mWM= (WindowManager) this.getBaseContext().getSystemService(Context.WINDOW_SERVICE);
ivCursor= new ImageView(getBaseContext());
ivCursor.setImageResource(com.example.jarmouse.R.drawable.ic_launcher);
mParams = new WindowManager.LayoutParams();//对ivCursor对象的参数描述对象
mParams.height = WindowManager.LayoutParams.WRAP_CONTENT;//宽度自适应
mParams.width = WindowManager.LayoutParams.WRAP_CONTENT;//高度自适应
mParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;//设置成不能获取焦点
mParams.type = LayoutParams.TYPE_PHONE;
//设置图片格式,效果为背景透明
mParams.format = PixelFormat.RGBA_8888;
mParams.gravity = Gravity.LEFT | Gravity.TOP;
mParams.x = 0;//相对于屏幕原点的x轴距离
mParams.y = 0;//相对于屏幕原点的y轴距离
mWM.addView(ivCursor, mParams);
}
当我把这段代码打包成jar 然后去调用mouse()这个方法的时候这两个会出现空指针异常
mWM= (WindowManager) this.getBaseContext().getSystemServic(Context.WINDOW_SERVICE);
ivCursor= new ImageView(getBaseContext());
把mouse()方法里的这段代码放到 oncreat方法中的时候就没问题
但是这样的话在引用这个jar包的程序虽然能正常运行 就是没有显示出一个浮动框
侃侃无极
鸿蒙传说
相关分类