Android Tools Attributes Reference (译)
来源:互联网 发布:孤岛惊魂3优化 编辑:程序博客网 时间:2024/06/12 20:46
官网地址:https://developer.android.google.cn/studio/write/tool-attributes.html
本文地址:http://blog.csdn.net/jjwwmlp456/article/details/55668486
Android Studio在tools命名空间中支持多种XML属性。当你构建你的应用,构建工具会删除这些属性,所以没有影响你的APK大小或运行时行为。
使用这些属性,需要添加tools命名空间到每个XML文件的根元素,如下所示:
<RootTag xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" >
属性中处理错误
以下属性将帮助抑制lint的警告消息。
tools:ignore
适合:任何元素
用于:Lint检查
这个属性接受一个以逗号分隔的lint问题id,达到忽略这个元素。例如,您可以告诉tools忽略MissingTranslation(缺失某语言的翻译)错误:
<string name="show_all_apps" tools:ignore="MissingTranslation">All</string>
tools:targetApi
适合:任何元素
用于:Lint检查
它的作用与@TargetApi一样。只是用于xml中。
例如,GridLayout在API level 14以上才支持:
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" tools:targetApi="14" >
当然,可以直接使用support v7库中的android.support.v7.widget.GridLayout
tools:locale
适合: <resources>
用于:Lint检查、Studio编辑器
在 <resources>中,为了避免拼写检查器的警告,可以使用tools:locale。它的值必须是一个有效的语言环境限定符
例如,在values/strings.xml中,表示默认字符串使用的语言是西班牙语,而不是英语:
<resources xmlns:tools="http://schemas.android.com/tools" tools:locale="es">
本文地址:http://blog.csdn.net/jjwwmlp456/article/details/55668486
设计时的View属性
以下布局中的属性定义,只有在studio布局预览时是可见的。
tools: instead of android:
适合: <View>
用于:Studio Layout编辑器
对任意的View的属性,使用”tools:”前缀,而不是使用”android:”前缀,就能在Layout预览时,看到你想要的效果
例如,在预览时,想看到TextView的text效果:
可以同时使用”tools:”前缀和”android:”前缀来操作同一属性。前者只影响布局时预览效果,后者影响运行时效果。
如下面的例子,会在Layout预览时,隐藏button2:
<Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="First" /><Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Second" tools:visibility="invisible" />
在Layout 预览编辑器中,设计时属性(即仅预览时有效的),旁边都有一个扳手图:
tools:context
适合: 任何 root <View>
用于:Lint 、Studio Layout编辑器
声明该layout默认用在哪个Activity上。那么在Layout编辑预览时,看到layout theme;在onClick时,通过quickfix,能创建对应方法在指定的Activity中。
可以使用点前缀的Activity类名,与清单文件中一样(不包括完整的包名称)。例如:
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity" >
tools:layout
适合: <fragment>
用于:Studio Layout编辑器
在<fragment>使用tools:layout,在预览时,就能看到fragment对应的layout:
<fragment android:name="com.example.master.ItemListFragment" tools:layout="@layout/list_content" />
tools:listitem / tools:listheader / tools:listfooter
适合: <AdapterView>(和一些类似<ListView>的子view)
用于:Studio Layout编辑器
在预览时,分别指定item、header、
<ListView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@android:id/list" android:layout_width="match_parent" android:layout_height="match_parent" tools:listitem="@layout/sample_list_item" tools:listheader="@layout/sample_list_header" tools:listfooter="@layout/sample_list_footer" /> <!--发现有意思的是,官网最后一句是:tools:listitem="@layout/sample_list_footer" —>
这三个属性,在Studio 2.2.2中还是不支持的,2.2.3中修复了
tools:showIn
适合: 被<include>的任意布局中的 root <View>
用于:Studio Layout编辑器
例如,在布局activity_main.xml中,<include>了如下layout,layout中又使用了tools:showIn=”@layout/activity_main”,这时就能在布局预览时,不光看到TextView,还能看到它的外布局activity_main了:
<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
适合: 任意布局中的 root <View>
用于:Studio Layout编辑器
这个属性指定菜单布局预览应该显示在应用程序栏中。值可以是一个或多个菜单ID,由逗号分隔(没有”@menu/”前缀或”.xml”扩展名)。如:
<?xml version="1.0" encoding="utf-8"?><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" />
本文地址:http://blog.csdn.net/jjwwmlp456/article/details/55668486
Resource 压缩属性
以下属性允许您启用严格的引用检查和声明,是保留还是丢弃某些资源,前提是启用了资源压缩。在build.gradle中,使用shrinkResources true,来启用资源压缩:
android { ... buildTypes { release { shrinkResources true minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } }}
tools:shrinkMode
适合: <resources>
用于:配置了资源压缩的构建工具
压缩模式。有两个取值:safe,保留所有被明确引用,或可能被 Resources.getIdentifier()动态引用的资源;strict,只保留被代码或其他资源所明确引用的。默认mode为safe。
<?xml version="1.0" encoding="utf-8"?><resources xmlns:tools="http://schemas.android.com/tools" tools:shrinkMode="strict" />
tools:keep
适合: <resources>
用于:配置了资源压缩的构建工具
声明保留的资源。可以是 一个以逗号分隔的列表,可以使用*通配符:
<?xml version="1.0" encoding="utf-8"?><resources xmlns:tools="http://schemas.android.com/tools" tools:keep="@layout/used_1,@layout/used_2,@layout/*_3" />
tools:discard
适合: <resources>
用于:配置了资源压缩的构建工具
声明丢弃的资源。可以是 一个以逗号分隔的列表,可以使用*通配符:
<?xml version="1.0" encoding="utf-8"?><resources xmlns:tools="http://schemas.android.com/tools" tools:discard="@layout/unused_1" />
关于资源压缩详见:压缩代码和资源文档
- Android Tools Attributes Reference (译)
- Android Studio Tools Attributes Reference
- Android - Designtime Layout Attributes & Tools Attributes
- Android Tools Attributes,让布局设计所见即所得
- Android Tools Attributes,让布局设计所见即所得
- Tools属性Tools Attributes
- Tools属性Tools Attributes
- CSS Attributes Reference
- Hibernate Tools Reference Guide
- Linux Devoloping Tools Reference
- Android preference XML Attributes
- [译]Android Tools属性
- Attributes
- Attributes
- $$Attributes
- android 中怎么样自定义attributes
- android tools
- android tools:
- 【NOIP2010】【模拟】T1 机器翻译 题解
- Android存储方式—SharePreferences存储
- theano CNN代码运行
- POI操作Excel常用方法总结
- 抽象工厂模式
- Android Tools Attributes Reference (译)
- Unity预计算全局光照的学习(速度优化,LightProbe,LPPV)
- [noip模拟]四道题 noip2010 机器翻译 noip2010 乌龟棋 noip 关押罪犯 noip 引水入城
- 仅需 90 秒,了解 WSS (主流 SOA 安全工具)
- CMT跟踪算法学习笔记
- 如何写出高质量的代码
- 使double保留两位小数的多方法 java保留两位小数
- unityUGUI拖拽物品的实现方法
- [省选] [最小生成树] [HLOI2016] 农场修路