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/