Android----獲取activity上所有的控件


01 /**
02      * @note 獲取該activity所有view
03      * @author liuh
04      * */
05     public List<View> getAllChildViews() {
06         View view = this.getWindow().getDecorView();
07         return getAllChildViews(view);
08     }
09  
10     private List<View> getAllChildViews(View view) {
11         List<View> allchildren = new ArrayList<View>();
12         if (view instanceof ViewGroup) {
13             ViewGroup vp = (ViewGroup) view;
14             for (int i = 0; i < vp.getChildCount(); i++) {
15                 View viewchild = vp.getChildAt(i);
16                 allchildren.add(viewchild);
17                 allchildren.addAll(getAllChildViews(viewchild));
18             }
19         }
20         return allchildren;
21     }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM