android - 在运行时检查 Android Activity 自己的 View 层次结构

标签 android view inspection view-hierarchy

Activity 是否有可能在不知道所有 View 的 ID 或特殊访问(例如检测模式或生根)的情况下访问并检查(理想情况下甚至修改)整个 View 层次结构?

例如是否可以编写一些代码来定位 Activity 的 View 层次结构中的所有 EditText 实例并对其执行某些操作?

谢谢

最佳答案

Is it possible for an Activity to get to and inspect, ideally even modify, the entire View hierarchy for itself, without special access such as instrumentation mode or rooting?

findViewById(android.R.id.content) 返回承载您在 setContentView() 中提供的内容的 View。除此之外,尝试 getRootView()(在任何 View 上调用)来检索“当前 View 层次结构中的最顶层 View ”。

关于android - 在运行时检查 Android Activity 自己的 View 层次结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15866453/

相关文章:

view - 在 View 中搜索文本

sql - 如何根据会计年度动态获取数据

android - 在 GridView 中显示图像的最佳方式是平滑滚动

android - 如何修复 Eclipse/Android 安装?图形 XML 编辑器中的 PNG 加载问题

java - 在指定的MSSQL-Schema中创建 View

python - Ruby 相当于 Python 的 "dir"?

intellij-idea - 谷歌 Guava checkNotNull 和 IntelliJ IDEA 的 "may produce java.lang.NullPointerException"

java - CDI:如何调试/检查?

android - Kotlin : How to use if-else like condition with let block for 'null' checks

android - 在 Android 中实现自定义的可绘制对象