【问题标题】:How to get child views of a ViewGroup in Android?如何在 Android 中获取 ViewGroup 的子视图?
【发布时间】:2012-10-24 11:26:50
【问题描述】:

我必须获得 WebView 的子视图。对于一些文本操作,不知有没有办法设置子视图的属性,例如:

View[] childs = webView.getChilds;
View ch = childs[0];
ch.setText("manipulated text");

【问题讨论】:

    标签: android view android-webview viewgroup


    【解决方案1】:

    WebView 有方法getChildCount()getChildAt(int index)。您可以尝试使用这些方法,但更好的解决方案是Bixi的。

    【讨论】:

      【解决方案2】:

      你为什么不使用 findViewById ?

      TextView subElement = (TextView) webview.findViewById(R.id.subelement);
      subElement.setText("Oh Hi");
      

      如果你真的想迭代孩子,你也可以使用ViewGroup::getChildAt()ViewGroup::getChildCount()

      【讨论】:

      • 我不知道内部视图,你能写一些应用代码吗?谢谢。
      • 所有你需要的都在我的帖子里,如果你需要代码示例:我强烈建议你阅读 Android 培训页面:developer.android.com/training/index.html,因为它是一些非常基本的 android 方法
      • findViewById() 对资源要求很高
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-13
      • 1970-01-01
      • 1970-01-01
      • 2012-05-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多