IllegalArgumentException: Window type can not be changed after the window is added

﹥>﹥吖頭↗ 提交于 2019-11-30 17:08:08
parik dhakan

Try to use this for window :

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                     WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_adjectives);

I run into the same question. But after stopping adding

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
requestWindowFeature(Window.FEATURE_NO_TITLE);

before super.onCreate(savedInstanceState); of BaseActivity, it works well. I cut and paste above codes before super.onCreate(savedInstanceState); of descends of BaseActivity.

BTW, I don't think you have to call super.onAttachedToWindow(); inside methods of life circle of Activity. Because onAttachedToWindow(); is called when the view is attached to a window when you overriding a View.

I also had this problem, but I solved it by removing the Window, changing the params and then adding the window again. This was good enough for me.

WindowManager.removeView(View); params = params2; //changed the params to something else WindowManager.updateViewLayout(View, params); WindowManager.addView(View, params);

Farhan Ghaffar

Sorry for late reply. You should add:

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

in onCreate method if you are using api level 15 or above. It works for me.

Sanjay sharma

Remove

this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG|WindowManager.LayoutParams.FLAG_FULLSCREEN);

From your onAttachedToWindow(), like this:

 @Override
     public void onAttachedToWindow() {
        //this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG|WindowManager.LayoutParams.FLAG_FULLSCREEN);

          super.onAttachedToWindow();
     }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!