如何将比特币标志写成文本?

How to write the Bitcoin logo as text?

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

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 中看到您的比特币符号,如下所示

Android 从 Android O 开始支持 Bitcoin Unicode 符号,您可以从这个 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);
    

结果,你会得到这个: