如何获得android的当前布局?

问题描述:

我的应用程序总是不同的布局如何获得android的当前布局?

A.xmlB.xmlC.xml

我想在当前布局AB执行disconnect()方法。

所以,如何获得android的当前布局?

+1

问题不清楚 – Krish

尝试这些:

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()