يتضمن تنفيذ TextView وجميع الفئات الفرعية المباشرة/غير المباشرة مع الدعم الأصلي لخطوط Roboto ، لوح الروبوتو الجديد و Roboto Mono Fonts.
الخطوط المدعومة:
يتم إهمال هذا المشروع لصالح التنفيذ الأصلي الذي تم تقديمه في Android O.
هذه المكتبة متوافقة من API 14 (Android 4.0).
Gradle:
compile ' com.github.johnkil.android-robototextview:robototextview:4.0.0 'مافن:
< 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 ); لتطبيق محرف Roboto لـ TextView الأصلي (مثل الخط) ، يجب إرفاق Inflater في فئة Activity الخاصة بك بطريقة #onCreate() .
@ 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's (Android Studio ، Intellij) هذا كخطأ على الرغم من صحة. قد ترغب في إضافة tools:ignore="MissingPrefix" إما إلى العرض نفسه أو مجموعة ViewGroup الأصل لتجنب ذلك. ستحتاج إلى إضافة مساحة اسم الأدوات للوصول إلى سمة "تجاهل". 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.