从最近的新版本 ADT 开始,我注意到布局 XML 文件中的这个新属性,例如:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity" />
什么是“工具:上下文”?
它甚至如何知道那里编写的 Activity 的确切路径?它是否在 list 中查看应用程序包?
它仅限于扩展 Context 的类还是仅限于 Activity ?是否可用于 ListView 项目等?
最佳答案
这是 UI 编辑器用于呈现布局预览的工具的 Activity。它记录在here :
This attribute declares which activity this layout is associated with by default. This enables features in the editor or layout preview that require knowledge of the activity, such as what the layout theme should be in the preview and where to insert onClick handlers when you make those from a quickfix
关于android - Android布局文件中的 "tools:context"是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11078487/