How to get all Views in an Activity?

后端 未结 5 613
太阳男子
太阳男子 2020-12-18 23:21

is there a way to get every view that is inside my activity? I have over 200 views including buttons, and images, so i want to be able to access them by using a loop

5条回答
  •  甜味超标
    2020-12-18 23:39

    To be specific:

    private void show_children(View v) {
        ViewGroup viewgroup=(ViewGroup)v;
        for (int i=0;i

    And then use the function somewhere:

    show_children(getWindow().getDecorView());
    

    to show all Views in the current Activity.

提交回复
热议问题