【问题标题】:Android extract string resource from layout xml fileAndroid从布局xml文件中提取字符串资源
【发布时间】:2013-07-05 16:16:31
【问题描述】:

我尝试从 xml 文件中提取硬编码字符串,但总是出错。 选择硬编码文本, ctrl+1 ,提取 android 字符串并弹出此错误,而不是弹出 Android 提取字符串。

“属性android:text不接受字符串引用”...

为什么我会收到此错误提示?

我使用 eclipse 3.7.1 和 adt v16,操作系统 windows 7。

This is the error

添加了显示该功能的视频 http://www.youtube.com/watch?feature=player_embedded&v=Oq05KqjXTvs#t=1881s

【问题讨论】:

    标签: android adt


    【解决方案1】:

    我刚刚找到了如何激活此功能。

    只需按“crtl+1”,就会弹出菜单。

    我也在寻找这个功能,直到我找到你的帖子......

    也感谢你的视频。

    【讨论】:

      【解决方案2】:

      我不太确定您要做什么,但我想给您一些提示,希望这能回答您的问题。

      首先,您应该在项目/res/value/strings.xml 中写入任何在运行时不会更改的字符串

      一个strings.xml条目示例:

          <string name="text_button">Any Text</string>
      

      现在您可以像这样在 XML 中访问此字符串:

          android:text="@string/text_button" />
      

      但是,您想在运行时访问此字符串吗?然后试试这个:

      TextView tv_1 = (TextView) findViewById(R.id.text1);
      String myText = tv_1.getText();
      

      然后阅读: http://developer.android.com/guide/topics/resources/accessing-resources.html

      【讨论】:

      • 感谢您的提示,但这不是我想要的。youtube.com/… 等一下。
      • 很好的通用提示,但不适用于该问题,因为他们专门询问 Eclipse 错误
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多