Nic*_*ell 22
假设contentView是通过添加的视图window.addContentView()
((ViewGroup) contentView.getParent()).removeView(contentView);
Run Code Online (Sandbox Code Playgroud)
试试吧
View youAddedView;
ViewGroup rootView = (ViewGroup) findViewById(android.R.id.content);
for (int i = 0; i < rootView.getChildCount(); i++) {
if(rootView.getChildAt(i) == yourAddedView) {
// do anything here
}
}
Run Code Online (Sandbox Code Playgroud)
如果您已经有了对视图的引用,您只需执行以下操作:
ViewGroup rootView = (ViewGroup) findViewById(android.R.id.content);
rootView.removeView(viewToRemove);
Run Code Online (Sandbox Code Playgroud)
而不是循环遍历 ViewGroup。
| 归档时间: |
|
| 查看次数: |
16371 次 |
| 最近记录: |