关闭

关于WindowManager的一个小问题was originally added here

标签: windowManager
603人阅读 评论(0) 收藏 举报
分类:


 WindowManager  :悬浮层   它的View显示在整个系统的最顶层,在设置属性后,此View则可以存在手机主窗口上


给windowManager添加overlay这个视图

LayoutInflater inflater = LayoutInflater.from(this);
overlay = (TextView) inflater.inflate(R.layout.overlay, null);
overlay.setVisibility(View.INVISIBLE);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
        LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.TYPE_APPLICATION,
        WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
        PixelFormat.TRANSLUCENT);
windowManager = (WindowManager)this.getSystemService(Context.WINDOW_SERVICE);
windowManager.addView(overlay, lp);

但是当我关闭此activity时会报如下错误:

   12801-12801/com.wjf.fw.mybus E/WindowManager﹕ Activity com.wjf.fw.mybus.ChangeCityActivity has leaked window android.support.v7.widget.AppCompatTextView{4279d760 I.ED.... ......I. 0,0-130,186} that was originally added here
    android.view.WindowLeaked: Activity com.wjf.fw.mybus.ChangeCityActivity has leaked window android.support.v7.widget.AppCompatTextView{4279d760 I.ED....


虽然此错误不影响应用使用,但毕竟是错误,应该去解决:当销毁activity时应去掉WindowManager的视图

@Override
protected void onDestroy() {
    super.onDestroy();
  windowManager.removeView(overlay);
}




0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:10770次
    • 积分:225
    • 等级:
    • 排名:千里之外
    • 原创:11篇
    • 转载:1篇
    • 译文:1篇
    • 评论:0条