폰트 설정

폰트 설정

◆ 색상

- 실제로 색상이 적용되는 View 객체의 상태에 따라 색상을 변경한다.

Color.BLUE 를 사용하거나 0XFF0000FF 를 사용할수 있다 .

◆ 폰트

- 폰트는 앱에서 사용할 수 있는 맞춤 글꼴을 정의한다. 글꼴은 개별 글꼴 파일 또는 글꼴모음 으로 res/font/filename.tff로 액세스 가능하다.

원하는 글씨체를 넣어 액세스 할 수 있다 .

폰트 예제

MainActivity.java

package com.justice.graphictext; import androidx.appcompat.app.AppCompatActivity; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Typeface; import android.os.Bundle; import android.view.View; public class MainActivity extends AppCompatActivity { class MyView extends View { public MyView(Context context) { super(context); setBackgroundColor(Color.YELLOW); } @Override protected void onDraw(Canvas canvas) { canvas.drawColor(Color.YELLOW); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setTextSize(100); Typeface t; t = Typeface.create(Typeface.DEFAULT, Typeface.NORMAL); paint.setTypeface(t); canvas.drawText("DEFAULT 폰트", 10, 400, paint); t = Typeface.create(Typeface.DEFAULT_BOLD, Typeface.NORMAL); paint.setTypeface(t); canvas.drawText("DEFAULT_BOLD 폰트", 10, 600, paint); t = Typeface.create(Typeface.MONOSPACE, Typeface.NORMAL); paint.setTypeface(t); canvas.drawText("MONOSPACE 폰트", 10, 800, paint); t = Typeface.create(Typeface.SERIF, Typeface.NORMAL); paint.setTypeface(t); canvas.drawText("SERIF 폰트", 10, 1000, paint); t = Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL); paint.setTypeface(t); canvas.drawText("SANS_SERIF 폰트", 10, 1200, paint); } } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); MyView w = new MyView(this); setContentView(w); } }

실행결과

from http://kimm6094.tistory.com/39 by ccl(A) rewrite - 2021-09-05 18:00:44