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

Comments

Projects
None yet
2 participants
@shaonialife

shaonialife commented Jul 3, 2017

在你的说明中关于如何拿到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

This comment has been minimized.

Show comment
Hide comment
@drakeet

drakeet Jul 3, 2017

Owner

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

Owner

drakeet commented Jul 3, 2017

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

@drakeet drakeet changed the title from 获取Context的问题 to 获取 Context 的问题 Jul 3, 2017

@drakeet

This comment has been minimized.

Show comment
Hide comment
@drakeet

drakeet Aug 13, 2017

Owner

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

Owner

drakeet commented Aug 13, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment