在 Fragment 的开发中,发现无法使用 this 字符来获取 fragment 的上下文。所以我们获取 fragment 的上下文时首先需要获取 fragment 对象。
View view = inflater.inflate(R.layout.fragment_home, container, false);
再调用 view 对象的 getContext 方法,来调用 Context 上下文。
转载请注明:隨習筆記 » Fragment 中获取 Context
在 Fragment 的开发中,发现无法使用 this 字符来获取 fragment 的上下文。所以我们获取 fragment 的上下文时首先需要获取 fragment 对象。
View view = inflater.inflate(R.layout.fragment_home, container, false);
再调用 view 对象的 getContext 方法,来调用 Context 上下文。
转载请注明:隨習筆記 » Fragment 中获取 Context