什么是“工具:上下文"?在 Android 布局文件中? [英] What's "tools:context" in Android layout files?

查看:26
本文介绍了什么是“工具:上下文"?在 Android 布局文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从最近的 ADT 新版本开始,我注意到布局 XML 文件上的这个新属性,例如:

Starting with a recent new version of ADT, I've noticed this new attribute on the layout XML files, for example:

<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" />

工具:上下文"的用途是什么?

它怎么知道写在那里的活动的确切路径?它是否查看清单中的应用程序包?

How does it even know the exact path to the activity that is written there? Does it look at the package of the app, inside the manifest?

它仅限于扩展上下文的类还是仅限于活动?它可用于 ListView 项目等吗?

Is it limited to classes that extend Context or only activities? Is it usable for ListView items etc.?

推荐答案

这是工具 UI 编辑器用来呈现布局预览的活动.它记录在此处:

This is the activity the tools UI editor uses to render your layout preview. It is documented here:

此属性声明此布局默认与哪个活动相关联.这将启用编辑器或布局预览中需要了解 Activity 的功能,例如预览中的布局主题应该是什么,以及当您从快速修复中创建 onClick 处理程序时在何处插入这些功能

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 布局文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆