码迷,mamicode.com
首页 > 移动开发 > 详细

手机桌面显示自定义View

时间:2016-08-06 12:39:59      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:

 

 

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;
        }

    }
}

  

手机桌面显示自定义View

标签:

原文地址:http://www.cnblogs.com/324sige/p/5743554.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!