您的位置:首页 > 移动开发 > Android开发

13.Android xmlns:tools 技巧

2015-09-20 22:56 411 查看

13.Android xmlns:tools 技巧

Android xmlnstools 技巧
tools 命名空间

tools ignore

tools targetApi

tools locale

tools context

tools layout

tools listitemtools listheadertools listfooter

tools showIn

tools menu

tools actionBarNavMode

tools 命名空间

xmlns:tools="http://schemas.android.com/tools"


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


tools ignore

可在任何 XML 元素上设置,表示了要在此元素或它的任何子元素上递归忽略的lint问题的ID。

<string name="miss" tools:ignore="MissingTranslation">miss</string>


tools targetApi

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

<LinearLayout tools:targetApi="ICE_CREAM_SANDWICH" >


tools locale

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

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


tools context

通常在一个布局XML文件的根元素中设置,标记了这个布局文件关联到的activity(注:但是,因为显然一个布局在设计时可以被多个布局使用)(例如它会用于布局编辑器中以推断默认的主题,由于主题定义在Manifest中,并与activity而不是布局相关联。你可以和在manifests中一样使用点前缀,来指定activity类,而不需要使用完整的程序包名作为前缀。

<android.support.v7.widget.GridLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity" ... >


tools layout

一般设置在
<fragment>
标签中,用来记录在设计时想看到渲染的布局 (在运行时,将由这个标签的fragment的类的操作所决定)。

<fragment android:name=".TestFragment" tools:layout="@android:layout/test_content" />


tools listitem、tools listheader、tools listfooter

可用于在设计时的
<ListView>
(或其他 AdapterView 的子类,比如
<GridView>
<ExpandableListView>
等) 来指定布局使用的列表项,以及列表头部和列表底部。该工具将填充假的数据,以显示一个有一些类似内容的列表。

<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:listitem="@android:layout/simple_list_item_2" />


tools showIn

设置于一个被其他布局
<include>
的布局的根元素上。这可以指向包含此布局的其中一个布局,在设计时这个被包含的布局会带着周围的外部布局被渲染。

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


tools menu

在布局的根元素上设置,用于配置在 ActionBar 中显示的菜单。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

在布局的根元素上设置,用于配置 ActionBar 使用的导航模式。值包括:“”standard”,“list”和“tabs”。需要 Studio 0.8.0 或更高版本。

<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" />
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息