ユーザ用ツール

サイト用ツール


サイドバー

android:viewのフォント追加

Viewのフォント追加

bdfフォントttfに変換してをAndroidに追加する

ビルドツールのインストール

wslのubuntです
 
# ビルドツールのインストール
$ sudo apt install build-essential
...
Do you want to continue? [Y/n] y
Ign:1 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 binutils-common amd64 2.30-20ubuntu2~18.04
Err:1 http://security.ubuntu.com/ubuntu bionic-updates/main amd64 binutils-common amd64 2.30-20ubuntu2~18.04
  404  Not Found [IP: 2001:67c:1560:8001::11 80]
...
 
# リポジトリ更新
$ sudo sed -i.bak -e "s%http://archive.ubuntu.com/ubuntu/%http://ftp.jaist.ac.jp/pub/Linux/ubuntu/%g" /etc/apt/sources.list
 
# やっぱりエラー
$ sudo apt install build-essential
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package build-essential
 
 
# aptアップデートが必要だった(これをしないとaptできない)
$ sudo apt update
 
# ビルドツールのインストール
$ sudo apt install build-essential
 
# 確認
$ gcc -version
gcc: error: unrecognized command line option ‘-version’
gcc: fatal error: no input files
compilation terminated.
bdf2ttfをcloneしてコンパイルする
$ git clone git@github.com:koron/bdf2ttf.git
$ cd bdf2ttf
$ cp compile/Make_gcc.mak makefile
$ make

// dbf を ttfに変換
$ ./bdf2ttf ayu20gothic-1.7a.ttf ./sample.ini ./ayu20gothic-1.7a/10x20grkm.bdf

↓ttfファイルができあがる

↓appにassetsフォルダを作成する。
 Target Source Set が「main」になっていることを確認して Finish。

↓assetsの中にfontディレクトリを作成する

↓ttfを貼り付ける。

# app.gradleに追加
implementation 'uk.co.chrisjenx:calligraphy:2.3.0'

       val am = this.getApplicationContext().getAssets()
       val typeface = Typeface.createFromAsset(am,String.format(Locale.US, "font/%s", "shnm6x12a.ttf"))
       
       もしくは
       
       val custom_font = Typeface.createFromAsset(assets, "font/shnm6x12a.ttf")
       
       ↓
       
       holder.textTitle?.typeface=typeface
       holder.textSub?.typeface=typeface
android/viewのフォント追加.txt · 最終更新: 2019/11/16 00:28 by ips