今天終於可以看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.』。有些可能搞不太懂得就繼續放著吧,看看以後會不會比較懂。