I would like to access the complete view hierarchy of an Activity. The native Views are easily accessible from their parent view using parent.getChildAt(int index)
method. I want to access the same for an activity that uses Composable Widgets.
For traversing the view hierarchy, I'm using the following code:
private void traverseHierarchy(Activity activity){
ViewGroup rootView = (ViewGroup)activity.getWindow().getDecorView();
traversalUtil(rootView);
}
private void traversalUtil(View view){
// code to process the view
if (view instanceof ViewGroup) {
int childCount = ((ViewGroup) view).getChildCount();
for(int i = 0; i < childCount; i++){
traversalUtil(((ViewGroup) view).getChildAt(i));
}
}
}
For activity using Composable widgets, the last parent accessible using the above code is of type AndroidComposeView and I'm unable to access the Composables drawn inside the AndroidComposeView.
Is there an alternative of viewGroup.getChildAt(int index) when working with Composables or AndroidComposeView?