Android 之 tools的作用

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_login"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.tanrong.note_client.ui.LoginActivity"
    tools:targetApi="14"
     tools:locale="es"
    tools:ignore="TextFields,HardcodedText,UselessParent">

1.tools:context的作用

tools:context就是指定这个XML布局文件对应的Acitivity

2.tools:igore的作用

tools:igore的作用就是忽略一些指定错误,或者 抑制警告

忽略全部:

xmlns:tools="http://schemas.android.com/tools"  
tools:ignore=“all”

显示所有警告的方法:Analyze -> Inspect Code; 就可以检查出所有的警告;

3、tools:targetApi

这个属性功能与Java代码中的@TargetApi注解相同:对元素指定支持的API级别。
告知tools,元素只用于指定的或更高的API级别。
例如因为GridLayout只适用于API级别14及以上,你可以使用它。

4、tools:locale

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

通知tools给定元素的默认语言/区域是什么,来避免拼写检查器的警告。该值必须是有效的区域设置限定符。
例如,可在values/strings.xml文件中添加来指定默认字符串的语言是西班牙语而不是英语

5、tools:layout

<fragment android:name="com.example.master.ItemListFragment"
    tools:layout="@layout/list_content" />

这个属性声明哪个布局在布局预览时画到fragment中

6、tools:listitem / tools:listheader / tools:listfooter

<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:listitem="@layout/sample_list_footer" />

这个属性指定在布局预览中显示列表的项,头部和尾部的布局。

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

允许指定一个布局就像include那样,这样可以预览这个文件就像他嵌入到父布局中。

8、tools:menu

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

这个属性指定在布局预览的AppBar中显示的菜单。该值可意识1个活多个菜单ID,以逗号分隔。

警告含义总结:http://blog.csdn.net/caroline_wendy/article/details/42245959

警告的类型可以通过文档进行查找: http://tools.android.com/tips/lint-checks
总结:https://blog.csdn.net/lihenair/article/details/53885027

扫描二维码关注公众号,回复: 3101412 查看本文章

猜你喜欢

转载自blog.csdn.net/zhangyDD/article/details/80353156