/**
*
* @author dlsdnd345
*
*/
public class BaseActivity extends Activity {
private static Typeface mTypeface;
private static Typeface mTypefaceBold;
@Override
public void setContentView(int layoutResID) {
super.setContentView(layoutResID);
if (BaseActivity.mTypeface == null){
BaseActivity.mTypeface = Typeface.createFromAsset(getAssets(), Config.FontType.SET_FONT);
BaseActivity.mTypefaceBold = Typeface.createFromAsset(getAssets(), Config.FontType.SET_FONT_BOLD);
}
ViewGroup root = (ViewGroup) findViewById(android.R.id.content);
setGlobalFont(root);
}
/**
* 최상위 ViewGroup 을 통해서 TextView 를 검색 하여 변경
* View 안에 감싸져 있는 TextView 는 재귀 함수를 통해 해결
* @param root
*/
void setGlobalFont(ViewGroup root) {
for (int i = 0; i < root.getChildCount(); i++) {
View child = root.getChildAt(i);
if (child instanceof TextView){
if(((TextView)child).getTypeface() != null){
if(((TextView)child).getTypeface().getStyle() == Typeface.BOLD){
((TextView)child).setTypeface(mTypefaceBold);
}
}else{
((TextView)child).setTypeface(mTypeface);
}
}
if (child instanceof EditText){
if(((EditText)child).getTypeface() != null){
if(((EditText)child).getTypeface().getStyle() == Typeface.BOLD){
((EditText)child).setTypeface(mTypefaceBold);
}
}else{
((EditText)child).setTypeface(mTypeface);
}
}
if (child instanceof Button){
if(((Button)child).getTypeface() != null){
if(((Button)child).getTypeface().getStyle() == Typeface.BOLD){
((Button)child).setTypeface(mTypefaceBold);
}
}else{
((Button)child).setTypeface(mTypeface);
}
}
if (child instanceof ViewGroup){
setGlobalFont((ViewGroup)child);
}
}
}
/**
*
* 위 코드와 동일 시점을 변경 하기 위해서 사용
* 레이아웃을 구성 하고 폰트를 변경하기 위함.
*/
void setGlobalFont() {
ViewGroup root1 = (ViewGroup) findViewById(android.R.id.content);
for (int i = 0; i < root1.getChildCount(); i++) {
View child = root1.getChildAt(i);
if (child instanceof TextView){
if(((TextView)child).getTypeface() != null){
if(((TextView)child).getTypeface().getStyle() == Typeface.BOLD){
((TextView)child).setTypeface(mTypefaceBold);
}
}else{
((TextView)child).setTypeface(mTypeface);
}
}
if (child instanceof EditText){
if(((EditText)child).getTypeface() != null){
if(((EditText)child).getTypeface().getStyle() == Typeface.BOLD){
((EditText)child).setTypeface(mTypefaceBold);
}
}else{
((EditText)child).setTypeface(mTypeface);
}
}
if (child instanceof Button){
if(((Button)child).getTypeface() != null){
if(((Button)child).getTypeface().getStyle() == Typeface.BOLD){
((Button)child).setTypeface(mTypefaceBold);
}
}else{
((Button)child).setTypeface(mTypeface);
}
}
if (child instanceof ViewGroup){
setGlobalFont((ViewGroup)child);
}
}
}
}
|