【问题标题】:Android: Error in parsing string from string.xmlAndroid:从 string.xml 解析字符串时出错
【发布时间】:2017-07-17 15:37:09
【问题描述】:

我已经在 String.xml 中指定了字符串值

<string name="complaint_fragment_type_label">Type</string>

在布局文件中作为

<TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:maxLines="1"
            android:text="@string/complaint_fragment_type_label"
            android:textSize="17sp"
            android:textStyle="bold" />

但我在 TextView 中获取字符串“Type”时出错。在 textview 中获取字符串的解决方案可能是什么?

【问题讨论】:

  • but i am having errors in getting the string "Type" in the TextView. 是什么错误?!!
  • 您的代码没有错误..您遇到了什么错误
  • 显示日志猫
  • 你在真机上测试过吗?看来您在 xml 文件中看到了
  • 我已经测试了你的代码,它工作正常。请发布你的错误日志

标签: android layout textview string.xml


【解决方案1】:

问题是因为 string.xml 不是值资源文件。您可以通过右键单击值目录然后选择新建来创建值资源文件,您将获得该选项。然后只需将其命名为 string 并在 &lt;resources&gt; 标签内添加 &lt;string&gt; 标签即可完成

【讨论】:

    【解决方案2】:
    <TextView
                android:id="@+id/textView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:maxLines="1"
                android:text="Complaint"
                android:textSize="17sp"
                android:textStyle="bold" />
    

    试试这个...

    【讨论】:

      猜你喜欢
      • 2015-10-23
      • 2011-08-13
      • 2018-03-14
      • 1970-01-01
      • 2017-09-26
      • 1970-01-01
      • 2012-10-04
      • 2016-07-11
      • 1970-01-01
      相关资源
      最近更新 更多