手机桌面显示自定义View
package com.example.mobile.Utils; import android.content.Context; import android.graphics.PixelFormat; import android.view.WindowManager; import android.widget.TextView; import android.widget.Toast; public class ToastUtils { private static WindowManager mWM; private static TextView view; public static void showInWindow(Context context,String text){ mWM = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); final WindowManager.LayoutParams params = new WindowManager.LayoutParams(); params.height = WindowManager.LayoutParams.WRAP_CONTENT; params.width = WindowManager.LayoutParams.WRAP_CONTENT; params.format = PixelFormat.TRANSLUCENT; params.type = WindowManager.LayoutParams.TYPE_TOAST; params.setTitle("Toast"); params.flags = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; view=new TextView(context); view.setText("啦啦啦德玛西亚"); mWM.addView(view, params); } public static void unShowInWindow(){ if (mWM!=null && view !=null){ mWM.removeView(view); view=null; } } }