gpt4 book ai didi

android - 图形布局编辑器的 "fragment providing context"下拉菜单有什么用?

转载 作者:太空宇宙 更新时间:2023-11-03 12:38:39 24 4
gpt4 key购买 nike

主题下拉菜单旁边有一个下拉菜单;它的悬停文本显示为“提供上下文的关联 Activity 或 fragment ”。

此(新)小部件未在图形布局编辑器中描述(或显示)documentation .

我假设这是一个通常显示此 View 的 Activity 或 fragment 。但是布局编辑器如何处理这些信息呢?它能以某种方式用于预览操作栏自定义吗?

enter image description here

最佳答案

Android tools blog记录如下:

We've added a new menu: The Activity chooser. This lets you choose the activity context to use for this layout:

enter image description here

When you open a layout the first time, we attempt to guess the right layout (by looking at your activity classes and seeing which layouts they reference), but you can choose a different activity here. The activity associated with a layout is used to pick which theme to render with, in the case where you've assigned themes to activities in your manifest file. You can also open the activity in the Java editor by choosing "Open activity name". In the future we will also use the activity<->layout association to drive other features.

我注意到更改此值后,一个新的 tools:context 属性被添加到 XML 中的顶级元素,这使我找到了这个 related question and answer .我还输入了 documentation bug report要求将其包含在文档中。

That attribute is basically the persistence for the "Associated Activity" selection above the layout. At runtime, a layout is always associated with an activity. It can of course be associated with more than one, but at least one. In the tool, we need to know about this mapping (which at runtime happens in the other direction; an activity can call setContentView(layout) to display a layout) in order to drive certain features.

Right now, we're using it for one thing only: Picking the right theme to show for a layout (since the manifest file can register themes to use for an activity, and once we know the activity associated with the layout, we can pick the right theme to show for the layout). In the future, we'll use this to drive additional features - such as rendering the action bar (which is associated with the activity), a place to add onClick handlers, etc.

The reason this is a tools: namespace attribute is that this is only a designtime mapping for use by the tool. The layout itself can be used by multiple activities/fragments etc. We just want to give you a way to pick a designtime binding such that we can for example show the right theme; you can change it at any time, just like you can change our listview and fragment bindings, etc.

(Here's the full changeset which has more details on this: https://android-review.googlesource.com/#/c/36273/ )

And yeah, the link Nikolay listed above shows how the new configuration chooser looks and works: http://tools.android.com/recent/newconfigchooser

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.

关于android - 图形布局编辑器的 "fragment providing context"下拉菜单有什么用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12502103/

24 4 0