0

I am developing an android app and I want to write the Bitcoin symbol in a TextView.
Is there any code for that like "\u20B9" for Rupees?

bitcoin symbol

Community
  • 1
  • 1

2 Answers2

2

Android supports Bitcoin Unicode symbol since Android O, you can read more about it from this link. Just try to run your code in Android O and I'm sure that everything will be fine.

But if still want to use TextView, to show BTC symbol, consider FontAwesome, it's actually designed for WEB, but it also possible to use in Android.

  1. Download icons pack.
  2. Put ttf font file to your assets folder
  3. Then get Typeface object and set it to your TextView:

    String fontName = "fa-brands-400.ttf";
    Typeface fontAwesome = Typeface.createFromAsset(getAssets(), "fonts/" + fontName);
    textView.setTypeface(fontAwesome);
    
  4. Add string XML resource with FontAwesome code point of BTC symbol:

    <string name="btc_fa">&#xf15a;</string>
    
  5. Set this string to TextView:

    textView.setText(R.string.btc_fa);
    

As the result, you will get this:

enter image description here

Denysole
  • 3,903
  • 1
  • 20
  • 28
1

Create a string in strings.xml like the following one:

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

Use the following to create the textView with BitCoin Symbol:

<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"/>

You will have your bitcoin symbol in textView like below

enter image description here

Rahul Sharma
  • 2,867
  • 2
  • 27
  • 40