androidviewinspectionview-hierarchy

Inspecting an Android Activity's own View hierarchy at runtime


Is it possible for an Activity to get to and inspect, ideally even modify, the entire View hierarchy for itself, without knowing IDs of all the views or special access such as instrumentation mode or rooting?

E.g. would it be possible to write some code that locates all, say, EditText instances in the Activity's View hierarchy and does something to them?

Thanks


Solution

  • Is it possible for an Activity to get to and inspect, ideally even modify, the entire View hierarchy for itself, without special access such as instrumentation mode or rooting?

    findViewById(android.R.id.content) returns the View that hosts the content you supplied in setContentView(). Beyond that, try getRootView() (called on any View) to retrieve "the topmost view in the current view hierarchy".