【发布时间】:2017-04-04 09:36:06
【问题描述】:
我的应用总是不同的布局
A.xml、B.xml、C.xml
我想在当前布局A 和B 执行disconnect() 方法时。
那么,如何在 android 上获取当前布局?
【问题讨论】:
-
问题不清楚
我的应用总是不同的布局
A.xml、B.xml、C.xml
我想在当前布局A 和B 执行disconnect() 方法时。
那么,如何在 android 上获取当前布局?
【问题讨论】:
试试这些:
View currentView = this.getWindow().getDecorView().findViewById(android.R.id.content)
或
View currentView = this.findViewById(android.R.id.content)
或
View currentView = this.findViewById(android.R.id.content).getRootView()
或
如果你给你的布局文件的每个根标签加上一个id,你可以得到视图,如下所示:
<RelativeLayout
android:id="@+id/rl_root_one"
然后获取视图:
RelativeLayout relativeLayout = (RelativeLayout)findViewById(R.id.rl_root_one);
使用上述任何一种方法,您都可以得到当前视图的膨胀。
【讨论】:
你可以用这个
this.getWindow().getDecorView().findViewById(android.R.id.content)
或者这个
this.findViewById(android.R.id.content).getRootView()
【讨论】: