【问题标题】:How to write the Bitcoin logo as text?如何将比特币徽标写成文本?
【发布时间】:2018-06-12 23:46:28
【问题描述】:

我正在开发一个 Android 应用程序,我想在 TextView 中写入比特币符号。
是否有类似“\u20B9”的卢比代码?

【问题讨论】:

  • 你试过\u20BF吗,因为这是建议的比特币符号。
  • 试试这个answer的unicodes
  • 是的。我试过但它不起作用@TentenPonce
  • @nileshprajapati 请检查下面给出的答案,让我知道它是否适合您。
  • 谁能告诉我这个问题有什么问题为什么投反对票(-1)?

标签: android unicode textview


【解决方案1】:

Android 支持Bitcoin Unicode 符号,因为Android O,您可以从link 中了解更多信息。只需尝试在Android O 中运行您的代码,我相信一切都会好起来的。

但如果还想用TextView,来显示BTC符号,考虑FontAwesome,它实际上是为WEB设计的,但也可以在Android中使用。

  1. Download 图标包。
  2. ttf字体文件放到你的assets文件夹中
  3. 然后获取Typeface 对象并将其设置为您的TextView

    String fontName = "fa-brands-400.ttf";
    Typeface fontAwesome = Typeface.createFromAsset(getAssets(), "fonts/" + fontName);
    textView.setTypeface(fontAwesome);
    
  4. 使用FontAwesome 代码点BTC 符号添加字符串XML 资源:

    <string name="btc_fa">&#xf15a;</string>
    
  5. 将此字符串设置为TextView:

    textView.setText(R.string.btc_fa);
    

结果,你会得到这个:

【讨论】:

    【解决方案2】:

    strings.xml 中创建一个字符串,如下所示:

    <string name="bitCoin">\u20BF</string>
    

    使用以下内容创建带有比特币符号的 textView:

    <TextView
            android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="16dp"
            android:layout_marginTop="16dp"
            android:text="@string/bitCoin"/>
    

    您将在 textView 中看到您的比特币符号,如下所示

    【讨论】:

    • 这是一个hack,不是真正的答案
    • @matrix 你试过实现它吗?请花一些时间并按照上述方式实施,您将在 android 上获得比特币符号。
    • 我没有说它不起作用。我只是说你不应该仅仅为了翻译一些 unicode 而创建字符串
    • @matrix 确实如此。我们不应该,但它可以满足需求,直到我们找到问题的最佳解决方案。
    • 刚刚试过这个,它有效。但我不确定它是否会在所有目标设备上显示 OK。
    猜你喜欢
    • 1970-01-01
    • 2013-11-29
    • 1970-01-01
    • 2014-01-17
    • 1970-01-01
    • 2014-04-22
    • 2016-09-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多