Get window token of the window to which decorview is attached

2k views Asked by At

How to get the window token of the window to which decorview is attached?

1

There are 1 answers

0
azizbekian On BEST ANSWER

If I have understood your question correctly, then this is my answer:


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

          }
        });