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

黑马程序员---手机卫士day4 自定义土司

时间:2015-02-11 10:55:33      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:安卓

自定义土司

首先得到一个 窗口管理器

WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);

通过窗口管理器 绑定一个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);






黑马程序员---手机卫士day4 自定义土司

标签:安卓

原文地址:http://blog.csdn.net/d342784178/article/details/43730847

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