Lalith Lalith - 4 years ago 1239
Android Question

Get root view from current activity

I know how to get the root view with View.getRootView(). I am also able to get the view from a button's

event where the argument is a View. But how can I get the view in an activity?

Answer Source

If you need root view of your activity (so you can add your contents there) use


please note that as Booger reported, this may be behind navigation bar (with back button etc.) on some devices (but it seems on most devices it is not).

If you need to get view that you added to your activity using setContentView() method then as pottedmeat wrote you can use

final ViewGroup viewGroup = (ViewGroup) ((ViewGroup) this

But better just set id to this view in your xml layout and use this id instead.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download