If you want to stick with the static method, use Activity instead of Context as a parameter and execute Activity.findViewById like this:
public static void displayLevelUp(int level, Activity activity) { LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.toastText, (ViewGroup) activity.findViewById(R.id.abs__action_bar_container));
Another way to do this is to pass the parent ViewGroup as a parameter instead of Context or Action:
public static void displayLevelUp(int level, ViewGroup rootLayout) { View layout = rootLayout.inflate(rootLayout.getContext(), R.layout.custom_level_coast, rootLayout.findViewById(R.id.toast_layout_root));
source share