工具属性

Android 有一个专用的XML命名空间,用于使工具可以记录XML文件里的信息,并且在打包程序的进行把信息剥离到不会带来运行时期和下载大小的负面影响的程度。 这个命名空间的 URI 是 http://schemas.android.com/tools,并且它通常被绑定到 tools: 前缀中:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>

这个tools标签主要是为adt插件使用的。他里面的很多属性能在很大程度上方便我们的开发,但是并不会影响我们最终生成的apk包。比如大家在写一个界面的时候一般都会给Textview写上text的值,然后在开发完毕的时候再删除他,这个操作就很麻烦,但是现在你就可以。

tools:ignore

此属性可以在任何 XML 元素上设置,它是一个逗号分割的lint 问题ID的列表,表示了应该要在此元素或它的任何子元素上递归忽略的lint问题的ID。

<string name="show_all_apps" tools:ignore="MissingTranslation">All</string>

tools:context

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

tools:context=".MainActivity"这一句不会被打包进APK。只是ADT的Layout Editor在你当前的Layout文件里面设置对应的渲染上下文,说明你当前的Layout所在的渲染上下文是activity name对应的那个activity,如果这个activity在manifest文件中设置了Theme,那么ADT的Layout Editor会根据这个Theme来渲染你当前的Layout。仅用于给你看所见即所得的效果而已。(One more thing: The "tools" namespace is special. The android packaging tool knows to ignore it, so none of those attributes will be packaged into the APK. We're using it for extra metadata in the layout. It's also where for example the attributes to suppress lint warnings are stored -- as tools:ignore.)

tools:targetApi

此属性像 Java 类中的 @TargetApi 批注解一样: 它允许您指定一个 API 级别,可以是整数或代码名称,表示此元素需要在此级别之上运行。

<GridLayout tools:targetApi="ICE_CREAM_SANDWICH"
.........
>

tools:text

<TextView
android:text="text"
tools:text="tools text"
.........
>

tools:text,其实就是给ADT用的,用于在design页面能够预览到这个属性的值,但是当实际上运行的时候是看不到这个值的。

tools:listitem / listheader / listfooter

是给ADT来让你预览listview布局的。

<ListeView
tools:listview="@android:layout/simple_list_item_1"
.........
>

tools:locale

此属性可以设置在资源文件的根元素上,并且应该对应于一种语言或一个地区。这会让工具知道文件的字符串被假定为哪种语言(区域)中的。例如, values/strings.xml 可以有此根元素:

<resources xmlns:tools="http://schemas.android.com/tools" tools:locale="es">

tools:layout

此属性通常设置在一个 标签中,用来记录在设计时你想看到渲染的布局 (在运行时,将由这个标签所列的fragment的类的操作所决定)。

<fragment
android:name=".MyFragment" tools:layout="@android:layout/list_content" />

tools:showIn

该属性设置于一个被其他布局的布局的根元素上。这让您可以指向包含此布局的其中一个布局,在设计时这个被包含的布局会带着周围的外部布局被渲染。这将允许您“在上下文中”查看和编辑这个布局。

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:showIn="@layout/activity_main" />

tools:menu

这个属性在布局的根元素上设置,用于配置在 Action Bar中显示的菜单。Android Studio 通过查看这个布局文件所链接的activity(通过 tools:context)里的onCreateOptionsMenu()方法,尝试找出哪些菜单在 ActionBar 中使用。它允许重写哪个搜索和显示声明的菜单用于显示。它的值是逗号分隔的 id 列表 (没有 @id/ 或任何这类前缀)。还可以使用没有.xml 扩展名的菜单xml文件的名称。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:menu="menu1,menu2" />

tools:actionBarNavMode

这个属性在布局的根元素上设置,用于配置 Action Bar 使用的导航模式。可能的值包括:“standard”,“list”和“tabs”。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:actionBarNavMode="tabs" />

更多

http://tools.android.com/tips/layout-designtime-attributes

我是天王盖地虎的分割线

Android -- tools的更多相关文章

  1. 解决 Could not find com.android.tools.build:gradle 问题

    今天拉同事最新的代码,编译时老是报如下错误: Error:Could not find com.android.tools.build:gradle:2.2.0.Searched in the fol ...

  2. Could not find com.android.tools.build:gradle:1.3.0.

    * What went wrong:          A problem occurred configuring project ':TZYJ_Android'.> Could not re ...

  3. Android requires compiler compliance level 5.0 or 6.0. Found '1.8' instead. Please use Android Tools>Fix project Properties.

    重装操作系统之后,或者破坏了Android的开发环境之后,需要重新配置好Android的开发环境.但是配置好后,导入原有的项目时,报错: Android requires compiler compl ...

  4. Failed to apply plugin [id 'com.android.application'] 和 Could not find com.android.tools.build:gradle:2.XX的最正确的解决方法

    发现android studio是真的可爱啊,上一秒还没问题可以build运行,下一秒就出错...好,你任性,你牛逼.. 说下今天又遇到的两个问题:Failed to apply plugin [id ...

  5. Could not find com.android.tools.build:aapt2:3.2.1-4818971.

    Could not find com.android.tools.build:aapt2:-. Searched in the following locations: file:/H:/Androi ...

  6. Android APP打包错误,Could not resolve com.android.tools.lint:lint-gradle:26.1.2.

    1.Please select the product flavors to build and sign 不专业的翻译一下(请选择产品的味道来制作和签名)什么鬼: 选中Flavors中的选项即可: ...

  7. android stdio Error Could not find com.android.tools common 25.2.2

    Error:Could not find com.android.tools:common:25.2.2. Searched in the following locations: file:/D:/ ...

  8. Centos Android开发环境配置-Android Tools -android list sdk --extended --all

    Centos Android开发环境配置-Android Tools -android  list sdk --extended --all 安装完Android Tools后执行 android   ...

  9. 解决 Could not resolve com.android.tools.build:gradle:3.1.3

      android studio 升级到3.1.3后总会遇到莫名其妙的错误,前几天刚解决了项目 dependencies报错的问题. 解决android studio 升级到3.0+之后 项目 dep ...

  10. GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.1.2/gradle-3

    Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.1.2/gradle-3 ...

随机推荐

  1. PHP 从基础开始 ——重要知识点笔记

    PHP static 关键词 通常,当函数完成/执行后,会删除所有变量.不过,有时我需要不删除某个局部变量.实现这一点需要更进一步的工作. 要完成这一点,请在您首次声明变量时使用 static 关键词 ...

  2. Spring MVC如何接收浏览器传递来的请求参数--request--形参--实体类封装

    阅读目录 1. 通过HttpServletRequest获得请求参数和数据 2. 处理方法形参名==请求参数名 3. 如果形参名跟请求参数名不一样怎么办呢?用@RequestParam注解 4. 用实 ...

  3. ElasticSearch-.net平台下c#操作ElasticSearch详解

    ElasticSearch系列学习 ElasticSearch第一步-环境配置 ElasticSearch第二步-CRUD之Sense ElasticSearch第三步-中文分词 ElasticSea ...

  4. Jquery中使用定时器setInterval和setTimeout

    直接在ready中调用其他方法,会提示缺少对象的错误,解决方法如下: 方法1. 函数不在$(function(){....})内,setInterval第一个参数为"showAtuto&qu ...

  5. C - 项目收藏

    Web框架 [荐]Kore:开源 C 语言 Web 框架 Raphters:A web framework for C ulfius:Web Framework for REST API in C, ...

  6. maria-developers 开发者邮件

    https://lists.launchpad.net/maria-developers/

  7. Revit API移动风管

    移动风管曲线就可以移动风管 , , ));//向上移动3         ts.Commit();         return Result.Succeeded;     } } url:http: ...

  8. 得到WAV文件的长度

    long getVideoLength (char *fileName){   MCI_OPEN_PARMS mciOpenParms;   MCI_STATUS_PARMS mciStatusPar ...

  9. Android 程序目录介绍

    还是回到 Eclipse 中,首先展开 HelloWorld 项目,你会看到如图 1.17 所示的目录结构. 图   1.17 一开始看到这么多陌生的东西,你一定会感到有点头晕吧.别担心,我现在就对上 ...

  10. 为 JIRA 6.x 安装中文语言包

    20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送) 国内私募机构九鼎控股打造,九鼎投资是在全国股 ...