什么是"工具:背景与QUOT;在Android的布局文件? [英] What's "tools:context" in Android layout files?

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

问题描述

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

 < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s
    机器人:方向=垂直
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    工具:上下文=。MainActivity/>
 

什么是工具:背景?用于

它是如何知道到是写有该活动的确切路径?它看起来在应用程序的包,里面的表现?

难道仅限于类,扩展上下文或仅活动?是它的ListView项目等使用。?

解决方案

这是最有可能的工具UI编辑器使用,以使您的布局的活动(它会发现基础上,活动的权利主题)。这一点已记录这里(围绕文章的中间;订阅该页面,不断更新)

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

What is "tools:context" used for?

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?

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

解决方案

This is most probably the activity the tools UI editor uses to render your layout (it will find the right theme based on the activity). This is documented here (around the middle of the article; subscribe to that page to keep up to date).

这篇关于什么是&QUOT;工具:背景与QUOT;在Android的布局文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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