I can't find a way to obtain a reference the Window
containing an arbitrary View
v. I found getWindowToken, but I can't figure out how to use it? Does anyone know how?
Also, does anyone know why it returns an IBinder
rather than a Window
?
I can't find a way to obtain a reference the Window
containing an arbitrary View
v. I found getWindowToken, but I can't figure out how to use it? Does anyone know how?
Also, does anyone know why it returns an IBinder
rather than a Window
?
Well... since all views have a reference of the activity that created them (Context
), you can use that Context
to get a reference of the window. Let me show you this example I wrote some minutes ago:
// main activity
import android.app.Activity;
import android.os.Bundle;
public class GetWindow extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MyView view = new MyView(this);
view.changeSomethingInWindow(); // keep an eye on this method
setContentView(view);
}
}
Then, inside your view you can do this:
// your view :D
import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
public class MyView extends View{
private Context mContext;
public MyView(Context context) {
super(context);
mContext = context;
}
public void changeSomethingInWindow(){
// get a reference of the activity
Activity parent = (Activity)mContext;
// using the activity, get Window reference
Window window = parent.getWindow();
// using the reference of the window, do whatever you want :D
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}
In this case, I change the mode the Window is displayed to Fullscreen. Hope this help you. Tell me if you get in trouble with this.