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

前端 未结 5 675
走了就别回头了
走了就别回头了 2021-01-03 21:21

I\'ve tried the advice here, the advice here, the advice here, I\'ve commented out the onAttachedToWindow() in my Base Activity. I have two Activities inheriting from this

相关标签:
5条回答
  • 2021-01-03 21:26

    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();
         }
    
    0 讨论(0)
  • 2021-01-03 21:27

    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.

    0 讨论(0)
  • 2021-01-03 21:28

    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.

    0 讨论(0)
  • 2021-01-03 21:32

    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);

    0 讨论(0)
  • 2021-01-03 21:47

    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);
    
    0 讨论(0)
提交回复
热议问题