Android-RobotoTextView


Source link: https://github.com/johnkil/Android-RobotoTextView

Android-RobotoTextView

Implementation of a TextView and all its direct/indirect subclasses with native support for the Roboto fonts, includes the brand new Roboto Slab and Roboto Mono fonts.

Supported fonts:

Deprecated 😢

This project is deprecated in favor of the native implementation introduced in Android O.

Compatibility

This library is compatible from API 14 (Android 4.0).

Download

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>

Usage

In XML

To set up a typeface you must specify the parameter 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"/>

or specify a set of parameters robotoFontFamily, robotoTextWeight and 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"/>

Set up typeface in code:

In Code

Using parameter typeface:

RobotoTextView textView = new RobotoTextView(context);
 RobotoTypefaces.setUpTypeface(

textView,

 RobotoTypefaces.TYPEFACE_ROBOTO_LIGHT_ITALIC);

Using parameters fontFamily, textWeight and textStyle:

RobotoTextView textView = new RobotoTextView(context);
 RobotoTypefaces.setUpTypeface(

textView,

 RobotoTypefaces.FONT_FAMILY_ROBOTO,

RobotoTypefaces.TEXT_WEIGHT_LIGHT,

RobotoTypefaces.TEXT_STYLE_ITALIC);

With Span

Using parameter 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);

Using parameters fontFamily, textWeight and 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 Inflater

To apply roboto typeface for original TextView (like a Calligraphy) you must attach inflater in your Activity class in the #onCreate() method.

@Override protected void onCreate(@Nullable Bundle savedInstanceState) {

  RobotoInflater.attach(this);

  super.onCreate(savedInstanceState);
 
}

and specify the typeface in 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"/>

Note: Popular IDE's (Android Studio, IntelliJ) will likely mark this as an error despite being correct. You may want to add tools:ignore="MissingPrefix" to either the View itself or its parent ViewGroup to avoid this. You'll need to add the tools namespace to have access to this "ignore" attribute. xmlns:tools=" http://schemas.android.com/tools". See https://code.google.com/p/android/issues/detail?id=65176.

Gradle

If you intend to use is not all fonts, the extra fonts can be removed.

android.applicationVariants.all{
 variant ->
  variant.mergeAssets.doLast {

File fonts = file("$variant.mergeAssets.outputDir/fonts")

if (fonts.exists()) {

 for (File file : fonts.listFiles()) {

  if (file.getName().contains("RobotoSlab")) {

println("delete " + file.getName() + " font")

file.delete()

  
}

 
}

}

  
}
 
}

License

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. 

Resources

This is the Android port of an NES emulator written in Go.

Android Library that shows a beautiful and customizable Material designed dialog with header.

An Intellij platform plugin to transforming SVG to android VectorDrawable.

The ultimate product information API, enabling a new breed of product-centric apps.

Persistent SearchView Library in Material Design.

AudioPlayerView is an Android view that loads audio from an url and have basic playback tools.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes