android - How to get view from context?

后端 未结 5 852
走了就别回头了
走了就别回头了 2020-12-01 04:26

I want to get the view or findViewById() from Context? Or from intent?

I\'m trying to reach a specific view in my broadcast receiver and the parameter of onReceive a

5条回答
  •  不思量自难忘°
    2020-12-01 04:51

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

    In Raw Android it'd look something like:

    View rootView = ((Activity)mContext).getWindow().getDecorView().findViewById(android.R.id.content)
    

    Then simply call the findViewById on this

    View v = rootView.findViewById(R.id.your_view_id);
    

提交回复
热议问题