Roboto Fonts에 대한 기본 지원을 갖춘 TextView 및 모든 직접/간접 서브 클래스의 구현에는 새로운 Roboto Slab 및 Roboto Mono Fonts가 포함됩니다.
지원되는 글꼴 :
이 프로젝트는 Android O에서 도입 된 기본 구현에 찬성하여 더 이상 사용되지 않습니다.
이 라이브러리는 API 14 (Android 4.0)에서 호환됩니다.
Gradle :
compile ' com.github.johnkil.android-robototextview:robototextview:4.0.0 'Maven :
< dependency >
< groupId >com.github.johnkil.android-robototextview</ groupId >
< artifactId >robototextview</ artifactId >
< version >4.0.0</ version >
< type >aar</ type >
</ dependency > 서체를 설정하려면 매개 변수 robotoTypeface 지정해야합니다.
< com .devspark.robototextview.widget.RobotoTextView
xmlns : android = " http://schemas.android.com/apk/res/android "
xmlns : app = " http://schemas.android.com/apk/res-auto "
android : layout_width = " wrap_content "
android : layout_height = " wrap_content "
app : robotoTypeface = " roboto_light_italic " /> 또는 매개 변수 세트를 지정하여 robotoFontFamily , robotoTextWeight 및 robotoTextStyle 지정하십시오.
< com .devspark.robototextview.widget.RobotoTextView
xmlns : android = " http://schemas.android.com/apk/res/android "
xmlns : app = " http://schemas.android.com/apk/res-auto "
android : layout_width = " wrap_content "
android : layout_height = " wrap_content "
app : robotoFontFamily = " roboto "
app : robotoTextWeight = " light "
app : robotoTextStyle = " italic " />코드에서 서체 설정 :
매개 변수 typeface 사용 :
RobotoTextView textView = new RobotoTextView ( context );
RobotoTypefaces . setUpTypeface (
textView ,
RobotoTypefaces . TYPEFACE_ROBOTO_LIGHT_ITALIC ); 매개 변수 사용 fontFamily , textWeight 및 textStyle 사용 :
RobotoTextView textView = new RobotoTextView ( context );
RobotoTypefaces . setUpTypeface (
textView ,
RobotoTypefaces . FONT_FAMILY_ROBOTO ,
RobotoTypefaces . TEXT_WEIGHT_LIGHT ,
RobotoTypefaces . TEXT_STYLE_ITALIC ); 매개 변수 typeface 사용 :
RobotoTypefaceSpan span = new RobotoTypefaceSpan (
context ,
RobotoTypefaces . TYPEFACE_ROBOTO_LIGHT_ITALIC );
Spannable spannable = new SpannableString ( "text" );
spannable . setSpan ( span , 0 , 1 , Spannable . SPAN_EXCLUSIVE_EXCLUSIVE ); 매개 변수 사용 fontFamily , textWeight 및 textStyle 사용 :
RobotoTypefaceSpan span = new RobotoTypefaceSpan (
context ,
RobotoTypefaces . FONT_FAMILY_ROBOTO ,
RobotoTypefaces . TEXT_WEIGHT_LIGHT ,
RobotoTypefaces . TEXT_STYLE_ITALIC );
Spannable spannable = new SpannableString ( "text" );
spannable . setSpan ( span , 0 , 1 , Spannable . SPAN_EXCLUSIVE_EXCLUSIVE ); 원본 TextView (서예)에 Roboto 서체를 적용하려면 #onCreate() 메소드의 Activity 클래스에 Laflater를 첨부해야합니다.
@ Override
protected void onCreate ( @ Nullable Bundle savedInstanceState ) {
RobotoInflater . attach ( this );
super . onCreate ( savedInstanceState );
}XML에서 서체를 지정하십시오.
< TextView
xmlns : android = " http://schemas.android.com/apk/res/android "
xmlns : app = " http://schemas.android.com/apk/res-auto "
android : layout_width = " wrap_content "
android : layout_height = " wrap_content "
app : robotoTypeface = " roboto_light_italic "
tools : ignore = " MissingPrefix " /> 참고 : 인기있는 IDE (Android Studio, Intellij)는 올바른 상태에도 불구하고 오류로 표시 할 것입니다. tools:ignore="MissingPrefix" 를 추가 할 수 있습니다. 이 "무시"속성에 액세스하려면 도구 네임 스페이스를 추가해야합니다. xmlns:tools=" http://schemas.android.com/tools" . https://code.google.com/p/android/issues/detail?id=65176을 참조하십시오.
사용하려는 것이 모든 글꼴이 아니라면 여분의 글꼴을 제거 할 수 있습니다.
android . applicationVariants . all{ variant ->
variant . mergeAssets . doLast {
File fonts = file( " $v ariant . mergeAssets . outputDir /fonts " )
if (fonts . exists()) {
for ( File file : fonts . listFiles()) {
if (file . getName() . contains( " RobotoSlab " )) {
println ( " delete " + file . getName() + " font " )
file . delete()
}
}
}
}
} Copyright 2014 Evgeny Shishkin
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.