public void showLoaction(String address) {
WindowManager.LayoutParams params = new LayoutParams();
params.height = WindowManager.LayoutParams.WRAP_CONTENT;
params.width = WindowManager.LayoutParams.WRAP_CONTENT;
params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;//指定固定在screen上
params.format = PixelFormat.TRANSLUCENT;//指定为半透明的
params.type = WindowManager.LayoutParams.TYPE_TOAST;
params.setTitle("Toast");
tView=new TextView(AddressService.this);
tView.setText("自定义Toast");
windowManager=(WindowManager) this.getSystemService(WINDOW_SERVICE);
windowManager.addView(tView, params);
}
在其他地方就可以引用,eg:
// Toast.makeText(getApplicationContext(),”自定义Toast”, 0).show();
showLoaction(address);