今天终于可以看Google Android SDK 开发范例大全 2这本书的03-03的变更TextView文字颜色 – 引用Drawable颜色常数及背景色这节了,你可以在http://book.51cto.com/art/200907/140343.htm看到简体版的文章!
这一节提到了几个新的方法:
public View findViewById (int id),Finds a view that was identified by the id attribute from the XML that was processed in onCreate(Bundle). Returns The view if found or null otherwise.
一开始乍看之下,会觉得课本的TextView跟View很类似,你继续查看View的连结可以知道TextView继承自View,基本上从Java来看,猫继承自动物,如果本来要传回的动物型别的话,现在改成猫的型别,似乎应该是要有点问题才对,但是好像很多资料叙述好像都没关系,那我们就继续看看情形吧!
getBaseContext()是ContextWrapper的一个方法,它会传回the base context as set by the constructor or setBaseContext,但是我查不到更详尽的资讯,ContextWrapper大概是‘Proxying implementation of Context that simply delegates all of its calls to another Context. Can be subclassed to modify behavior without changing the original Context.’。有些可能搞不太懂得就继续放着吧,看看以后会不会比较懂。