Title의 TextView 얻어오기
간단하게 아래와 같은 방법으로 TextView 를 얻어와서 setTypeface 를 하는 방법이다.
try {
Integer titleId = Resources.getSystem().getIdentifier("action_bar_title", "id", "android");
TextView title = (TextView) getWindow().findViewById(titleId);
// check for null and manipulate the title as see fit
title.setTextColor(getResources().getColor(R.color.black));
title.setTypeface(face);
} catch (Exception e) {
Log.e(TAG, "Failed to obtain action bar title reference");
}
TypefaceSpan
이 방법보다 추천되는 것은 TypefaceSpan 이라는 Custom Class 를 사용하는 것이다.SpannableString s = new SpannableString("My Title");
s.setSpan(new TypefaceSpan(this, "MyTypeface.otf"), 0, s.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
// Update the action bar title with the TypefaceSpan instance
ActionBar actionBar = getActionBar();
actionBar.setTitle(s);
TypefaceSpan 의 source code 는 ref. 1 을 참고 하기 바란다.
<project>\assets\fonts 폴더(context.getApplicationContext().getAssets())에 font 파일을 넣고, 사용하면 된다.
👍
답글삭제