【问题标题】:Android Button with text+®Android Button with text®
【发布时间】:2014-05-21 15:08:20
【问题描述】:

我正在尝试做一个包含文本(公司名称)+R(注册符号)的简单按钮,但我还需要 R 是文本的上标,如下所示: http://www.geofonica.com/graphics/gf-logo.gif

【问题讨论】:

标签: android button


【解决方案1】:

上标注册商标符号的 html 代码显示为 Google®

 <string name=company_name">Company name<sup>&#174;</sup></string> 

在你的文本视图中

   <TextView
    android:id="@+id/txt_company"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/company_name"/>

然后使用方法Html.fromHtml()

【讨论】:

    【解决方案2】:

    如果你真的有代码,我认为你可以这样做:

    ((TextView)findViewById(R.id.text)).setText(Html.fromHtml("<sup>&#174;</sup>"));
    

    否则,我认为只假设一个上标 R 可能是可以接受的。

    ((TextView)findViewById(R.id.text)).setText(Html.fromHtml("<sup>R</sup>"));
    

    希望对你有帮助。

    来源:http://developer.android.com/guide/faq/commontasks.html#selectingtext

    【讨论】:

      【解决方案3】:

      使用Html.fromHtml,您可以在TextView、Button 等中显示html(至少是一个子集)...

      可以在android button text and html找到一个很好的例子

      对于已注册的符号,您可以将其编码为 html entity ® &amp;#174;

      要在上标中显示符号,您可以使用 html 标签&lt;sup&gt;&lt;/sup&gt;

      【讨论】:

        【解决方案4】:

        使用“注册商标标志”的html代码,®

        显示类似: 公司名称 ®

        实现这一点的两种方法:

        1) 添加到您的strings.xml 文件中

        <string name=company_name">Company name &#174;</string>
        

        并将该字符串加载到您的布局中

         <TextView
                android:id="@+id/txt_company"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/company_name"/>
        

        2) 使用方法Html.fromHtml()

        ((TextView)findViewById(R.id.text)).setText(Html.fromHtml("Company name &#174;"));
        

        【讨论】:

        • OP 希望 (R) 被上标。
        • 是的 Eleanasys 上标更小,最多可达公司名称。
        猜你喜欢
        • 1970-01-01
        • 2014-10-22
        • 2020-08-15
        • 2022-08-08
        • 1970-01-01
        • 2014-04-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多