1. 程式人生 > >tools:context=".MainActivity的作用

tools:context=".MainActivity的作用

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world"
        tools:context=".MainActivity" />


一直對於 tools:context=".MainActivity"這句不懂,今天查了下,發現是這樣的:

tools:context="activity name"這一句不會被打包進APK。只是ADT的Layout Editor在你當前的Layout檔案裡面設定對應的渲染上下文,說明你當前的Layout所在的渲染上下文是activity name對應的那個activity,如果這個activity在manifest檔案中設定了Theme,那麼ADT的Layout Editor會根據這個Theme來渲染你當前的Layout。就是說如果你設定的MainActivity設定了一個Theme.Light(其他的也可以),那麼你在視覺化佈局管理器裡面看到的背景阿控制元件阿什麼的就應該是Theme.Light的樣子。僅用於給你看所見即所得的效果而已。