工具的目的是什么:openDrawer="start";从向导创建 DrawerLayout(带有 NavigationView)时? [英] What's the purpose of tools:openDrawer="start" when creating a DrawerLayout (with NavigationView) from the wizard?

本文介绍了工具的目的是什么:openDrawer="start";从向导创建 DrawerLayout(带有 NavigationView)时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Android Studio 中创建带有导航抽屉的 Activity 会导致其显示在 XML 代码中:

Creating an activity with navigation drawer in Android Studio causes this to be shown in the XML code:

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

如果我删除 tools:openDrawer="start",在布局预览中,导航抽屉将关闭而不是打开.

If I remove the tools:openDrawer="start", on the layout preview, the navigation drawer will be closed instead of open.

我认为这是一个替换属性,类似于 android:text 可以替换为 tools:text 以在布局预览中放置一些占位符文本.但是当我将其更改为android:openDrawerapp:openDrawer 时,应用程序无法编译,因为它们是未知属性.

I thought this was a replacement attribute, similar to android:text that can be replaced with tools:text to put some placeholder text in the layout preview. But when I change it to android:openDrawer or app:openDrawer, the app can't be compiled because they are unknown attributes.

所以我想知道 tools:openDrawer 是如何工作的,以及它是否被记录在任何地方.

So I wonder how tools:openDrawer works, and whether it is documented anywhere.

推荐答案

Android 有一个专用的 XML 命名空间,旨在供工具使用在 XML 文件中记录信息,并删除该信息当应用程序打包时没有运行时或下载大小惩罚.命名空间 URI 是http://schemas.android.com/tools 并且通常绑定到工具:前缀:

Android has a dedicated XML namespace intended for tools to be able to record information in XML files, and have that information stripped when the application is packaged such that there is no runtime or download size penalty. The namespace URI is http://schemas.android.com/tools and is usually bound to the tools: prefix:

这意味着 tools 属性由 IDE 使用,而不是在代码功能中使用.

This means that tools attribute is used by the IDE and not used in the code functionality.

我仍在尝试查找所有 tools 属性的完整文档.我在任何地方都找不到 openDrawer 属性.但以下是关于 tools 的很棒的文档:

I am still trying to find the complete documentation of all tools attributes. I can't find out the openDrawer attribute anywhere. But the following are great documentation on tools:

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

更新

现在可以使用所有 tools 属性的完整文档这里.

Now a complete documentation of all tools attribute is available here.

这篇关于工具的目的是什么:openDrawer="start";从向导创建 DrawerLayout(带有 NavigationView)时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆