回答

1

如果我理解正確你的問題,那麼這就是我的回答:

 

    getWindow().getDecorView().addOnAttachStateChangeListener(
     new View.OnAttachStateChangeListener() { 
      @Override public void onViewAttachedToWindow(View v) { 
      getWindow().getDecorView().removeOnAttachStateChangeListener(this); 
      IBinder binder = v.getWindowToken(); 
      } 

      @Override public void onViewDetachedFromWindow(View v) { 

      } 
     });