Android -- tools
工具属性
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的更多相关文章
- 解决 Could not find com.android.tools.build:gradle 问题
今天拉同事最新的代码,编译时老是报如下错误: Error:Could not find com.android.tools.build:gradle:2.2.0.Searched in the fol ...
- Could not find com.android.tools.build:gradle:1.3.0.
* What went wrong: A problem occurred configuring project ':TZYJ_Android'.> Could not re ...
- 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 ...
- 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 ...
- 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 ...
- 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中的选项即可: ...
- 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:/ ...
- Centos Android开发环境配置-Android Tools -android list sdk --extended --all
Centos Android开发环境配置-Android Tools -android list sdk --extended --all 安装完Android Tools后执行 android ...
- 解决 Could not resolve com.android.tools.build:gradle:3.1.3
android studio 升级到3.1.3后总会遇到莫名其妙的错误,前几天刚解决了项目 dependencies报错的问题. 解决android studio 升级到3.0+之后 项目 dep ...
- 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 ...
随机推荐
- 深入理解指针—>结构体里的成员数组和指针
单看这文章的标题,你可能会觉得好像没什么意思.你先别下这个结论,相信这篇文章会对你理解C语言有帮助.这篇文章产生的背景是在微博上,看到@Laruence同学出了一个关于C语言的题,微博链接.微博截图如 ...
- bzoj 3673 可持久化并查集
本质上是维护两个可持久化数组,用可持久化线段树维护. /************************************************************** Problem: ...
- 吴恩达-coursera-机器学习-week8
十三.聚类(Clustering) 13.1 无监督学习:简介 13.2 K-均值算法 13.3 优化目标 13.4 随机初始化 13.5 选择聚类数 十四.降维(Dimensionality Red ...
- PHP 命名空间与自动加载机制介绍
include 和 require 是PHP中引入文件的两个基本方法.在小规模开发中直接使用 include 和 require 没哟什么不妥,但在大型项目中会造成大量的 include 和 requ ...
- Mac 10.12彻底关闭Dashboard
1.打开[系统偏好设置]. 2.点击进入[Mission Control]. 3.中间有一项[Dashboard],点击它右边的下拉菜单,选择[关闭],即可.
- BootstrapClassloader ExtClassloader AppClassloader
http://www.importnew.com/26269.html import java.net.URL; class test9 { public static void main(Str ...
- C#写UTF8文件时指定是否含BOM头
BOM的基本概念 在UCS 编码中有一个叫做"ZERO WIDTH NO-BREAK SPACE"的字符,它的编码是FEFF.而FFFE在UCS中是不存在的字符,所以不应该出现在实 ...
- Linux学习9-CentOS搭建nginx环境
前言 之前我们搭建网站的时候,把war包放到tomcat下就能运行起来了,为什么部署上线的时候,又用到了nginx呢? nginx可以做多台服务器的负载均衡,当用户非常少的时候,可以用一台服务直接部署 ...
- java单例模式实例
什么是单例模式? 定义:确保一个类只有一个实例,而且自行实例化并向整个系统提供这个实例场景,也就是说:确保某个类有且只有一个对象的场景,避免产生多个对象消耗过多的资源,或者某种类型的对象应该有且只有一 ...
- Module ngx_http_v2_module
官方配置说明: http://nginx.org/en/docs/http/ngx_http_v2_module.html#example ngx_http_v2_module模块指令中文说明 ngx ...