TypefaceHelper
1.0.0
안드로이드의 다양한 텍스트보기에 서체를 주입하기위한 도우미 개체.
텍스트보기 (텍스트 뷰, 버튼, radiobutton, edittext 등)와 같은 모든 텍스트보기에 다양한 사용자 정의 서체 자산을 사용할 수 있지만, 앱의 전체 화면에 서체를 적용하기 위해 서체를 스타일 테마로 설정할 수있는 방법은 없습니다.
이 라이브러리는 쉽게 수행하는 데 도움이됩니다 :)
또한 자산 자원에서 서체를 작성하면 메모리 누출이 발생할 수있는 심각한 버그가 있습니다 (자세한 내용은이 링크 참조)이 라이브러리 도이 문제에 대해서도 관리합니다.
먼저 서체를 asset 디렉토리에 넣으십시오.
응용 프로그램 클래스에서는 도우미 객체 수명주기에주의하십시오.
public class MyApp extends Application {
@ Override
public void onCreate () {
super . onCreate ();
TypefaceHelper . initialize ( this );
}
@ Override
public void onTerminate () {
TypefaceHelper . destroy ();
super . onTerminate ();
}
}활동에서 서체를 텍스트보기로 설정하려면
public class MyActivity extends Activity {
@ Override
public void onCreate ( Bundle savedInstanceState ) {
super . onCreate ( savedInstanceState );
setContentView ( R . layout . activity_main );
TextView hello = ( TextView ) findViewById ( R . id . hello_world );
TypefaceHelper . getInstance (). setTypeface ( hello , "font/font_file.ttf" );
}
}이와 같은 특정보기 그룹에 속하는 모든 텍스트보기에 대한 서체를 설정할 수도 있습니다.
public class MyActivity extends Activity {
@ Override
public void onCreate ( Bundle savedInstanceState ) {
super . onCreate ( savedInstanceState );
setContentView ( R . layout . activity_main );
LinearLayout container = ( LinearLayout ) findViewById ( R . id . text_container );
TypefaceHelper . getInstance (). setTypeface ( container , "font/font_file.ttf" );
}
}활동 레이아웃에서 모든 텍스트보기에 서체를 적용하려면
public class MyActivity extends Activity {
@ Override
public void onCreate ( Bundle savedInstanceState ) {
super . onCreate ( savedInstanceState );
setContentView ( TypefaceHelper . getInstance (). setTypeface ( this , R . layout . activity_main , "font/font_file.ttf" ));
}
}멋지고 쉽습니다!
이와 같이 서체를 전체 창에 적용 할 수 있습니다.
public class MyActivity extends Activity {
@ Override
public void onCreate ( Bundle savedInstanceState ) {
super . onCreate ( savedInstanceState );
setContentView ( R . layout . layout_activity_main );
TypefaceHelper . getInstance (). setTypeface ( this , "font/font_file.ttf" );
}
}그리고 ... 글꼴 이름을 문자열 자원 ID로 전달할 수도 있습니다.
public class MyActivity extends Activity {
@ Override
public void onCreate ( Bundle savedInstanceState ) {
super . onCreate ( savedInstanceState );
setContentView ( R . layout . layout_activity_main );
TypefaceHelper . getInstance (). setTypeface ( this , R . string . font_primary );
}
}Gradle :
compile 'com.drivemode:TypefaceHelper:1.2.0@aar'
Copyright (C) 2014 Drivemode, Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
샘플 앱은 OFL 아래의 다음 글꼴을 사용합니다.