黑马程序员---手机卫士day4 自定义土司
自定义土司
首先得到一个 窗口管理器
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);
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。