Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

获取 Context 的问题 #152

Closed
shaonialife opened this issue Jul 3, 2017 · 2 comments
Closed

获取 Context 的问题 #152

shaonialife opened this issue Jul 3, 2017 · 2 comments

Comments

@shaonialife
Copy link

在你的说明中关于如何拿到Context说到:在 Android 开发中,任何 View 对象都能通过 view.getContext() 拿到 Context 对象,这些对象本质上都是 Activity 对象的引用。
实际上当Activities 继承至 AppCompatActivity时。从 23.3.0 开始 View.getContext() 返回的是
TintContextWrapper 而不是 Activity,一些用到Context的地方并不会出现什么问题,但是将Context强转成Activity就会报错了,详见 https://stackoverflow.com/questions/38814267/android-support-v7-widget-tintcontextwrapper-cannot-be-cast

@drakeet
Copy link
Owner

drakeet commented Jul 3, 2017

是的,你说的对,感谢指出!晚点时间更正。

@drakeet drakeet changed the title 获取Context的问题 获取 Context 的问题 Jul 3, 2017
@drakeet drakeet closed this as completed Jul 3, 2017
@drakeet
Copy link
Owner

drakeet commented Aug 13, 2017

目前发现,至少在使用 26.0.0 版 support 库时,View.getContext() 返回的确实是 Activity,看来官方已经改正了这个设计了。wiki 看起来可以改回来了。

@drakeet drakeet reopened this Aug 13, 2017
@drakeet drakeet closed this as completed Aug 18, 2017
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants