硬编码字符串"Test",应该使用@string资源

Edl*_*dli 6 android-layout

嗨,大家好,我是新来的,这是我的第一个问题

这是我的代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >



<TextView

    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/ref"    
 />

<TextView

    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Test"
 />
Run Code Online (Sandbox Code Playgroud)

我不想在第二次测试中使用字符串我该怎么办?

Tun*_*glu 14

没问题,你正在使用硬编码的字符串.如果您需要更多信息,请查看:https://stackoverflow.com/a/8743887/1517996

strings.xml中

<resources>
    <string name="Test">Test</string> 
<resources>
Run Code Online (Sandbox Code Playgroud)

并使用它像lin布局文件

<TextView

    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/Test"
 />
Run Code Online (Sandbox Code Playgroud)