机器人 - 如何获得视图的背景下? [英] android - How to get view from context?
问题描述
我想从上下文的观点或findViewById()? 或意图是什么?
I want to get the view or findViewById() from Context? Or from intent?
我想在我的广播接收器达到特定的视图和的onReceive的参数是上下文和意图。
I'm trying to reach a specific view in my broadcast receiver and the parameter of onReceive are context and intent.
嗯,我有一个类,并在其中是我的广播接收器。现在,我试图广播接收机从中分离出来,但我需要一种方法,所以我仍然可以从我的分离广播接收器类上我的课的意见沟通。
Well, I have a class and within it is my broadcast receiver. Now, I'm trying to separate the broadcast receiver from it, but I need a way so I can still communicate with the views on my class from my separated broadcast receiver class.
感谢。
推荐答案
与上下文开始,相关活动的根视图可以通过
Starting with a context, the root view of the associated activity can be had by
View rootView = ((Activity)_context).Window.DecorView.FindViewById(Android.Resource.Id.Content);
在原始的Android它会是这个样子:
In Raw Android it'd look something like:
View rootView = ((Activity)mContext).getWindow().getDecorView().findViewById(android.R.id.content)
然后,只需调用findViewById在此
Then simply call the findViewById on this
View v = rootView.findViewById(R.id.your_view_id);
这篇关于机器人 - 如何获得视图的背景下?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!