简体   繁体   English

如何在SystemUI类中获取当前活动的当前视图或应用程序上下文

[英]How to get Current View or Application Context of Current Activity in a class of SystemUI

I have a big problem. 我有一个大问题。 In systemUI/PhoneStatusBar class, I want to add a childView to parrent of current View of running Activity . systemUI/PhoneStatusBar类中,我想将childView添加到正在运行的Activity的当前View的Parrent中。 How to done it in PhoneStatusBar.java in systemUI . 如何在PhoneStatusBar.java中完成此systemUI I tried to using some method, example 我尝试使用一些方法,例如

View.getRootView() 

or so on, but cannot get expected result. 等等,但无法获得预期的结果。 Hope to get success from everyone. 希望从大家那里获得成功。 Thanks very much 非常感谢

Thanks for help from you. 感谢您的帮助。 But i would like to emphasized that "I want to get current view of running activity". 但是我想强调一下“我想了解跑步活动的最新观点”。 I it must be done in android/frameworks/base/packages//Systemui/statusbar/phone/PhoneStatusBar.java. 我必须在android / frameworks / base / packages // Systemui / statusbar / phone / PhoneStatusBar.java中完成。 I very very hope to continue receiving helps from everyone 我非常希望继续得到大家的帮助

Try 尝试

View.getContext(); View.getContext();

It should work. 它应该工作。

To add a view, you need to cast it as a ViewGroup: 要添加视图,您需要将其强制转换为ViewGroup:

ViewGroup addViewHere = (ViewGroup)myView;

Or you may need to get the parent if the problem is that you cannot add the view to the correct place in the view hierarchy: 或者,如果问题是您无法将视图添加到视图层次结构中的正确位置,则可能需要获取父视图:

ViewGroup addViewHere = (ViewGroup)myView.getParent();

Then assuming all layout params are correct, add it: 然后假设所有布局参数正确,将其添加:

addViewHere.addView(newView);

You can try this: 您可以尝试以下方法:

findViewById(android.R.id.content).getRootView()

It should give you the root view of the activity including status bar on top 它应该给您活动的根视图,包括顶部的状态栏

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM