我第一次从Xamarin开始创建一个Android应用程序,因此我遵循最基本的Xamarin Android tutorial。我到了为UI控件编辑Strings.xml文件的地步。我这样做,然后编译并得到:
C:\...\main.xml(0,0): Error: No resource found that matches the given name (at 'text' with value '@string/hello'). (AndroidHello)
我没有main.xml,但确实有Main.axml,该文件显然是通过解决方案生成的。是否需要编辑此文件以使其与.cs文件匹配?这似乎根本不对。还是应该以某种方式从.cs重新生成它?
我四处搜寻以尝试更多地了解.axml文件,因此我知道它们可用于指定布局,而不是在C#代码中指定。所以我以为我可以只删除.axml文件而仅依赖C#,但是从我的C#代码中引用时,我在Strings.xml中指定的任何Resource.String.resource都将不起作用。
Strings.xml。
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="helloButtonText">Say Hello</string>
<string name="helloLabelText">Hello Xamarin.Android</string>
</resources>
如前所述,.axml文件引用了不再存在的字符串。我该如何解决?
最佳答案
您可能在main.axml文件中定义了以下Button:
<Button
android:id="@+id/MyButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/Hello" />
替换@ string / Hello,您应该一切顺利。如果您更改了string.xml,则“ @ string / helloButtonText”可能是您需要的替换,或者只是“说你好”。