java - android eclipse错误:Error: no resource found that matches the given name (at 'text' with value '@string/red' )

标签 java android eclipse android-2.2-froyo

这确实让我有点疯狂,因为我正在学习 Android 教程之一,而且我已经遇到了两个问题。

首先是当我申请android:gravity="center"时文本仅垂直居中,而不是水平居中,如果我更改 helloworld 示例 textview android:text="@string/red" ,情况会更糟然后转到 strings.xml 并将默认值更改为 <string name="red">redflashlight</string>图形布局将文本显示为 @string/red而不是“redflashlight”

这是令人担忧的,因为我实际上正在遵循视频教程,并且我正在做作者正在做的事情,我担心也许它是 sdk 或 eclipse 的问题?也许我的操作系统是vista?我真的不知道,任何帮助都会非常感谢。

这是我的 main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
>    
<TextView  
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="@string/red"
/>
</LinearLayout>

这是我的 strings.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="red">redflashlight</string>
<string name="app_name">simple flashlight</string>
</resources>

最佳答案

使文本垂直和水平居中,

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
><TextView  
android:gravity="center_horizontal"
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="@string/red"
/></LinearLayout>

我尝试了你的代码,它工作正常。我认为你的项目没有正确构建。因此,构建它: 从 Eclipse 的菜单栏中选择“项目”->“自动构建”。

关于java - android eclipse错误:Error: no resource found that matches the given name (at 'text' with value '@string/red' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7238630/

相关文章:

Androidplot 如何隐藏绘图中的域值?

java - 获得响应之前 Volley 的响应时间

java - 在特殊情况下,Eclipse 无法生成 getter 和 setter;需要帮助追踪问题

eclipse - 有没有自动优化Eclipse.ini文件的插件?

java - Intellij插件开发中如何获取java文件的所有方法列表

android - 如何强制使用 HTTPS Google Maps Android API V1 & V2

java - 您推荐将哪个 JavaScript 库与 Java EE + Struts + iBatis 一起使用?

eclipse - 基于 Eclipse 中构建路径的自动编译器合规性选择? (或相反亦然?)

java - 我的 main 方法采用的输入参数是什么?

java - 在没有本地 persistence.xml 的情况下使用 JPA @StaticMetamodel 类? (远程 EJB)