android - Android布局文件中的 "tools:context"是什么?

标签 android xml android-layout android-context android-tools-namespace

从最近的新版本 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/

相关文章:

android - 开发 Android 主屏幕

python - (Python Scipy) 如何展平 csr_matrix 并将其附加到另一个 csr_matrix?

xml - 使用 XSLT 合并相等的命名空间前缀

java - 工具栏干扰使用 SearchView 过滤 RecyclerView

java - Glide 过渡中断变换

java - Android 和 Java 无法解析为类型

xml - 解析 git 日志输出,最好是 xml

android - 如何为水平recyclerview制作页面指示器

android - 为什么 marginBottom 不起作用?

java - 嵌套的 postDelayed/Runnable/Handler Android