手机卫士 自定义土司

自定义土司

首先得到一个 窗口管理器

WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);

wm是一个充满屏幕的窗口 只是在窗口中显示了view

通过窗口管理器 绑定一个view 和窗口参数params 就能生成一个土司 土司的显示内容就是view的内容

wm.addView(view, params);

示例:

<span style="white-space:pre">		</span>view = View.inflate(this, R.layout.address_show, null);
		TextView textview = (TextView) view.findViewById(R.id.tv_address);

		// "半透明","活力橙","卫士蓝","金属灰","苹果绿"
		int[] ids = { R.drawable.call_locate_white,
				R.drawable.call_locate_orange, R.drawable.call_locate_blue,
				R.drawable.call_locate_gray, R.drawable.call_locate_green };
		SharedPreferences sp = getSharedPreferences("config", MODE_PRIVATE);
		view.setBackgroundResource(ids[sp.getInt("which", 0)]);
		textview.setText(address);
		// 窗体的参数就设置好了
		WindowManager.LayoutParams params = new WindowManager.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;
		params.format = PixelFormat.TRANSLUCENT;
		params.type = WindowManager.LayoutParams.TYPE_TOAST;
		
		wm.<strong>addView</strong>(view, params);


代码注册receiver

<span style="white-space:pre">		</span>// 用代码去注册广播接收者
		receiver = new OutCallReceiver();
		//意图匹配器
		<strong>IntentFilter</strong> filter = new IntentFilter();
		//指定要过滤得到的行为
		filter.<strong>addAction</strong>("android.intent.action.NEW_OUTGOING_CALL");
		//(注册)绑定action到receiver
		<strong>registerReceiver</strong>(receiver, filter);






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值