遍历GroupView的所有子项?

遍历GroupView的所有子项?,第1张

遍历GroupView的所有子项?

您需要递归遍历视图树。当前,您仅列出根视图的子级。

换句话说,您需要这样的东西:

@Overridepublic void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.main);    ...    Typeface font = Typeface.createFromAsset(getAssets(), "fonts/choco.ttf");      ViewGroup rootView = (ViewGroup) findViewById(android.R.id.content).getRootView();    applyFontRecursively(rootView, font);}void applyFontRecursively(ViewGroup parent, Typeface font) {        for(int i = 0; i < parent.getChildCount(); i++)    {        View child = parent.getChildAt(i);         if(child instanceof ViewGroup)         { applyFontRecursively((ViewGroup)child, font);        }        else if(child != null)        { Log.d("menfis", child.toString()); if(child.getClass() == TextView.class) {     ((TextView) child).setTypeface(font); }        }         }}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/4926724.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-12
下一篇2022-11-12

发表评论

登录后才能评论

评论列表(0条)

    保存