我怎样才能让我的布局文件,以显示其标签为别人做什么?我的、人做、布局、为别

2023-09-12 05:53:32 作者:晚风吹

在大多数情况下,增加一个活动创建一个相应的布局(XML)文件,在操作栏显示[ActivityName](我不知道这是正确的术语)的布局。

In most cases, adding an Activity creates a corresponding Layout (xml) file that shows "[ActivityName]" in the Action Bar (I don't know if that's the correct terminology) of the Layout.

然而,在一种情况下,事实并非如此。

However, in one case, that is not so.

通过AndroidManifest.xml中是这样的:

With AndroidManifest.xml like this:

<activity
    android:name="hhs.app.VerifyCodeActivity"
    android:label="@string/title_activity_verify_code" >
</activity>
<activity
    android:name="hhs.app.DeliveryItemActivity"
    android:label="@string/title_activity_delivery_item" >
</activity>

...在布局的操作栏验证codeActivity空话是应用程序的名字,而不是活动名称(活动名称显示为DeliveryItemActivity的相应的版式文件)。

...the verbiage on the Action Bar of the Layout for VerifyCodeActivity is the appname, NOT the Activity name (the Activity name displays for the DeliveryItemActivity's corresponding Layout file).

该验证codeActivity布局应该说是验证code,因为这是在\值\的strings.xml文件:

The VerifyCodeActivity Layout should say "Verify Code" because this is in the \values\strings.xml file:

<string name="title_activity_verify_code">Verify Code</string>

抓住救命稻草(任何其他code不同),我在AndroidManifest.xml中改变了这一点:

Grasping at straws (anything different from other code), I changed this in AndroidManifest.xml:

android:name=".VerifyCodeActivity"

...这样的:

...to this:

android:name="hhs.app.VerifyCodeActivity"

...但它没有什么区别。这是怎么回事/我该如何解决这个问题?

...but it makes no difference. What's going on/how can I solve this?

下面就是我所说的 - 一个活动显示字幕我想它:

Here's what I'm talking about -- one Activity shows the caption I would like it to:

别人不一样,像这样的:

Others do not, such as this one:

我不明白为什么第二个不工作(它显示了应用程序的名称(HHS),而不是活动特定的字符串)。再次,标签都被设置在AndroidManifest.xml中,如上所示... ???

I can't see why the second one doesn't work (it shows the app name ("HHS") instead of the Activity-specific string). Again, the labels are both set in AndroidManifest.xml, as shown above...???

好了,很明显现在:AndroidManifest.xml中设置活动的标签,以一个特定的字符串(title_activity_settings),这是在strings.xml中:

Okay, it's obvious now: AndroidManifest.xml sets the Activity's label to a specific string (title_activity_settings), which is in strings.xml:

<string name="title_activity_settings">HHS Settings</string>

...但是,这对在设计时活动的布局文件没有任何影响,因为布局文件有在这一点上没有任何联系的活动。它是只被调用的活动后进行连接:

...but that has no effect on the Activity's layout file at design time, because the Layout file has no connection to the Activity at that point. It is only after the Activity is invoked that the connection is made:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_settings);
}

的字符串(在我的情况还是模仿的时候,)适用于活动的操作栏,然后,在运行时。

The string is applied to the Activity's Action Bar then, at run time (or "emulate time," in my case).

推荐答案

这是作为设计的完全合乎逻辑的。

This is "as designed" and completely logical.

AndroidManifest.xml中的活动的标签设置为一个特定的字符串(title_activity_settings),这是在strings.xml中:

AndroidManifest.xml sets the Activity's label to a specific string (title_activity_settings), which is in strings.xml:

<string name="title_activity_settings">HHS Settings</string>

...但是,这对在设计时活动的布局文件没有任何影响,因为布局文件有在这一点上没有任何联系的活动。它是只被调用的活动后进行连接:

...but that has no effect on the Activity's layout file at design time, because the Layout file has no connection to the Activity at that point. It is only after the Activity is invoked that the connection is made:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_settings);
}

那时,也只有这样,才能在AndroidManifest.xml中设置串应用到活动的操作栏。

Then and only then is the string set in AndroidManifest.xml applied to the Action Bar of the Activity.

之所以串显示器还在设计时在一种情况下是因为这在布局文件:

The reason why the string displays also at design time in one case is because of this in the Layout file:

tools:context="hhs.app.DeliveryItemActivity"

在上下文中:

<TableLayout 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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="hhs.app.DeliveryItemActivity">

    <TableRow
    . . .