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

这是我的问题,据说“从未使用过命名空间声明”

<RelativeLayout 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">
    <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="josh appear here"
    android:id="@+id/josh_text_view"
    />

    <Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="open Second Activity"
    android:layout_below="@+id/josh_text_view"
    android:onClick="showJosh"
    android:id="@+id/button" />

    <Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="open Third Activity"
    android:onClick="showJosh"
    android:id="@+id/button2"

在每个按钮中都有这个警告总是弹出

[I18N] 硬编码字符串“打开第二个活动”,应该少使用@string 资源... (Ctrl+F1) 直接在布局文件中硬编码文本属性是不好的,原因如下:

  • 创建配置变化时(例如横向或纵向),您必须重复实际文本(并在进行更改时保持最新)

  • 仅通过为现有字符串资源添加新翻译,无法将应用程序翻译成其他语言。在 Android Studio 和 Eclipse 中,有一些快速修复程序可以自动将此硬编码字符串提取到资源查找中。

            android:layout_below="@+id/button"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_marginTop="10dp" />
    
            <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="open Fourth Activity"
            android:onClick="showJosh"
            android:id="@+id/button3"
    
            android:layout_below="@+id/button"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_marginTop="75dp" />
    
    </RelativeLayout>
    
4

1 回答 1

0

Namespace declaration is not used is not an error. It's just a warning. You can delete that line if you want to but you can just leave it alone. Regarding the use of @string resource , it is considered best practice to define your string values inside the strings.xml file and reference them in your project. The strings.xml file is inside your res>values folder. For example: Inside your strings.xml file, there should be already some string resources present. Add the following line to the file

<string name="openThird">open Third Activity</string>

Now, inside your layout file, do this

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/openThird"
android:onClick="showJosh"
android:id="@+id/button2"

Do the same with your other buttons. Define the string values inside your strings.xml and then use them in your layout.

于 2015-05-20T02:24:45.757 回答