【问题标题】:Cannot set button text to "<<<"无法将按钮文本设置为“<<<”
【发布时间】:2018-10-28 01:36:01
【问题描述】:

我正在尝试从我的 xml 将按钮的文本设置为“

    <Button
        android:id="@+id/test"
        android:text="<<<"
        android:layout_width="wrap_content"
        android:layout_height="match_parent" />

所以我跳到我的 strings.xml 并在那里输入它,这显然行不通。

<string name="abc"> <<< </string>

有解决办法吗?

【问题讨论】:

    标签: java android button settext


    【解决方案1】:

    这些是 html 实体,也可以在 android studio 中使用:

    > can be replaced with &gt;
    < can be replaced with &lt;
    " can be replaced with &quot;, &ldquo; or &rdquo;
    ' can be replaced with &apos;, &lsquo; or &rsquo;
    } can be replaced with &#125;
    & can be replaced with &amp;
    space can be replaced with &#160;
    

    【讨论】:

      【解决方案2】:

      你可以使用

      < (less-than)                     &#60; or &lt;
      > (greater-than)                  &#62; or &gt;
      & (ampersand)                     &#38; or &amp;
      ' (apostrophe or single quote)    &#39; or &apos;
      " (double-quote)                  &#34; or &quot;
      

      请查看以下链接:

      Predefined entities in XML

      Using Special Characters in XML

      Stackoverflow - escaping special characters like & in android xml

      【讨论】:

        【解决方案3】:

        &amp;gt; 用于&gt;&amp;lt; 用于&lt;&amp;amp; 用于&amp;&amp;apos; 用于'&amp;quot; 用于"

        【讨论】:

          猜你喜欢
          • 2017-04-05
          • 1970-01-01
          • 1970-01-01
          • 2016-10-05
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多