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

Overview

Android-RobotoTextView

Android Arsenal

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:

image

Get it on Google Play

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.
Comments
  • Issue with any version above 2.2.0

    Issue with any version above 2.2.0

    Hi! I've got issues with the lib if using any version above 2.2.0, starting with 2.3.0. FOA the text in EditText looks like it has gravity top (2.2.0 - everything is ok) and if I tap the editbox the text vanishes like its textcolor becames white on white bg editText but the bigger issue gere - no keyboard appears so I'm unable to enter any text into editText. Also buttons starts ignoring gravity of its text, so the text label with v 2.2.0 is centered but if I switch to 2.3.0 text appears at left instead. You could see the diff here - http://prntscr.com/akfos1 The same applies to latest 2.50 version. I don't use appCompat.v7 in my app but olny support.v4 of 23.1.1 version. However adding appcompat.v7 lib to build.gradle does not change anything. EditText are locked from entering text and almost every TextView/EditText looks like it has gravity top. Every single layout appears broken and looks strange...

    opened by stan-ko 10
  • AppCompat v21 support.

    AppCompat v21 support.

    Hello,

    After adding AppCompat v21 library the controls are not tinted correctly (they are black). Is it possible to update RobotoTextView to work with AppCompat?

    See https://chris.banes.me/2014/10/17/appcompat-v21/ FAQ for more details.

    Thanks,

    improvement 
    opened by mkrasnowski 9
  • Do not try to use custom font in Eclipse Layout Editor

    Do not try to use custom font in Eclipse Layout Editor

    Does not set custom font if isInEditMode() is true to avoid errors (and the text not appearing at all) in the Eclipse Layout Editor.

    isInEditMode() requires API level 3 so I have increased the minSdkVersion.

    opened by intrications 6
  • Not compiles if compileSdk/targetSdk was set lower than 23

    Not compiles if compileSdk/targetSdk was set lower than 23

    Project can't be compiled if compileSdk/targetSdk was set lower than 23. It happens on 2.4.1 version also. But 2.4.0 version can be compiled successfuly.

    So, I'm getting an error message: ...\build\intermediates\exploded-aar\com.android.support\appcompat-v7\23.0.0\res\values-v23\values-v23.xml Error:(2) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Inverse'. Error:(2) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Button.Colored'.

    opened by VyacheslavShmakin 5
  • Android studio preview

    Android studio preview

    Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in java.lang.RuntimeException: Font asset not found fonts/RobotoSlab-Bold.ttf
        at android.graphics.Typeface.createFromAsset(Typeface.java:190)
        at com.devspark.robototextview.util.RobotoTypefaceManager.createTypeface(RobotoTypefaceManager.java:314)
        at com.devspark.robototextview.util.RobotoTypefaceManager.obtainTypeface(RobotoTypefaceManager.java:45)
        at com.yoavst.timetable.ui.views.NextLessonView.getCalendarView(NextLessonView.java:69)
        at com.yoavst.timetable.ui.views.NextLessonView.init(NextLessonView.java:51)
        at com.yoavst.timetable.ui.views.NextLessonView.initPreview(NextLessonView.java:43)
        at com.yoavst.timetable.ui.views.NextLessonView.<init>(NextLessonView.java:34)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
        at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:379)
        at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:99)
        at com.android.tools.idea.rendering.LayoutlibCallback.loadView(LayoutlibCallback.java:172)
        at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:207)
        at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:132)
        at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:806)
        at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)
        at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:809)
        at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)
        at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:809)
        at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)
        at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:809)
        at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)
        at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:809)
        at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
        at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:401)
        at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:329)
        at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:350)
        at com.android.tools.idea.rendering.RenderService$5.compute(RenderService.java:688)
        at com.android.tools.idea.rendering.RenderService$5.compute(RenderService.java:677)
        at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:932)
        at com.android.tools.idea.rendering.RenderService.createRenderSession(RenderService.java:677)
        at com.android.tools.idea.rendering.RenderService.render(RenderService.java:815)
        at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.doRender(AndroidLayoutPreviewToolWindowManager.java:646)
        at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.access$1700(AndroidLayoutPreviewToolWindowManager.java:82)
        at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7$1.run(AndroidLayoutPreviewToolWindowManager.java:589)
        at com.intellij.openapi.progress.impl.ProgressManagerImpl$2.run(ProgressManagerImpl.java:178)
        at com.intellij.openapi.progress.ProgressManager.executeProcessUnderProgress(ProgressManager.java:209)
        at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:212)
        at com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcess(ProgressManagerImpl.java:171)
        at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7.run(AndroidLayoutPreviewToolWindowManager.java:584)
        at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:320)
        at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:310)
        at com.intellij.util.ui.update.MergingUpdateQueue$2.run(MergingUpdateQueue.java:254)
        at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:269)
        at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:227)
        at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:217)
        at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)
        at com.intellij.util.Alarm$Request$1.run(Alarm.java:327)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
        at java.util.concurrent.FutureTask.run(FutureTask.java:262)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)
    
    opened by yoavst 3
  • Crash on Android Lollipop

    Crash on Android Lollipop

    I have the following error showing up on the layout preview

    Exception Details java.lang.NullPointerException   at 
    android.content.res.BridgeResources.getAnimation(BridgeResources.java:292)   at 
    android.animation.AnimatorInflater.loadStateListAnimator(AnimatorInflater.java:95)   at 
    android.view.View.<init>(View.java:4016)   at android.widget.TextView.<init>(TextView.java:629)   at 
    android.widget.Button.<init>(Button.java:111)   at android.widget.Button.<init>(Button.java:107)   at 
    android.widget.Button.<init>(Button.java:103)   at 
    com.devspark.robototextview.widget.RobotoButton.<init>(RobotoButton.java:59)   at 
    java.lang.reflect.Constructor.newInstance(Constructor.java:526)   at 
    android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:802)   at 
    android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)   at 
    android.view.LayoutInflater.rInflate(LayoutInflater.java:778)   at 
    android.view.LayoutInflater.inflate(LayoutInflater.java:500)   at 
    android.view.LayoutInflater.inflate(LayoutInflater.java:381)
    

    This lead to a crash on the Activity.setContentView()

     Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f070067 type #0x1d is not valid
            at android.content.res.Resources.loadXmlResourceParser(Resources.java:2603)
            at android.content.res.Resources.getXml(Resources.java:1098)
            at android.transition.TransitionInflater.inflateTransition(TransitionInflater.java:75)
            at com.android.internal.policy.impl.PhoneWindow.getTransition(PhoneWindow.java:3696)
            at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3649)
            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:367)
            at android.app.Activity.setContentView(Activity.java:2144)
    

    By looking at the code I think it searches for the animation xml added in Lollipop (for ripple effects and touch related animations). Is there a way to bypass this exception, without having to rewrite the whole layout for v21?

    EDIT: After some testing it appears that the library is not the cause of the crash, instead the style I used for the button is:

      style="?android:buttonBarButtonStyle"
    

    The second problem was the android:accentColor in the Material theme being #rrggbb instead of #aarrggbb

    bug 
    opened by dadino 3
  • Add Roboto Slab fonts

    Add Roboto Slab fonts

    Added this to my fork although I'm only presuming the licence of the new fonts is the same as the other Roboto fonts so you may not want to merge them until they are officially released by Google.

    opened by intrications 3
  • AAPT fails when using both RobotoTextView library and AppCompat library

    AAPT fails when using both RobotoTextView library and AppCompat library

    With appcompat-v7 version 26+, both RobotoTextView and AppCompatTextView attempt to declare

    <attr name="fontFamily">
    

    However, for AppCompat its format is "string", whereas for RobotoTextView it's "enum"

    Gradle build will fail with something like

    /Users/ddennis/project/app/build/intermediates/res/merged/release/values/values.xml:194: error: Attribute "fontFamily" already defined with incompatible format.
    /Users/ddennis/project/app/build/intermediates/res/merged/release/values/values.xml:5: Original attribute defined here.
    
    opened by dennisdrew 2
  • Gradle plugin for removing unused fonts

    Gradle plugin for removing unused fonts

    Somthing like this:

    apply plugin: 'com.android.application'
    apply plugin: 'com.devspark.robototextview.gradle-plugin'
    
    android {
        ....
    }
    
    robototextview {
        include 'Roboto-Regular', 'Roboto-Medium'
        // or
        exclude 'RobotoMono'
    }
    
    dependencies {
        ...
    }
    

    What do you think?

    opened by OlegKrikun 2
  • Add support for

    Add support for "smallcaps" typeface

    I'm seeing a new fontFamily: sans-serif-smallcaps in my project. I'm guessing this was added in Lollipop.

    The font used is a non Roboto font, but I was wondering if it could be added to this library. I'd not prefer using another library just for that font :)

    *Update: * The font is CarroisGothicSC-Regular

    opened by saket 2
  • Russian rouble gliph in pre-lollipop android

    Russian rouble gliph in pre-lollipop android

    I found a problem that pre-lollipop android versions don't have russian rouble sign (\u20bd). Can you update fonts on https://www.google.com/fonts/specimen/Roboto - it has necessary symbol

    opened by dmitrikudrenko 2
Releases(4.0.0)
Owner
Evgeny Shishkin
Senior Android Developer
Evgeny Shishkin
A simple and flexible Checked TextView or Checkable TextView

CheckableTextView Checkable TextView [KOTLIN] ⚡ A simple and flexible Checked TextView or Checkable TextView written in Kotlin ⚡ What's New Animation

null 110 Nov 20, 2022
Mentions-TextView - Make Mentions and hashtags clickable in Textview

Mentions Textview Custome Textview with Mentions and hashtags being clickable. D

null 2 Jan 9, 2022
A TextView that automatically resizes text to fit perfectly within its bounds.

AutoFitTextView A TextView that automatically resizes text to fit perfectly within its bounds. Usage dependencies { compile 'me.grantland:autofitt

Grantland Chew 4.2k Jan 1, 2023
A TextView that changes its content automatically every few seconds

FadingTextView A TextView that changes its content automatically every few seconds Demo app A demo app is available on Google Play: Usage Add this to

Tomer Rosenfeld 1.7k Dec 9, 2022
AutoLinkTextView is TextView that supports Hashtags (#), Mentions (@) , URLs (http://), Phone and Email automatically detecting and ability to handle clicks.

AutoLinkTextView Deprecated Please use the new version of AutoLinkTextView AutoLinkTextView is TextView that supports Hashtags (#), Mentions (@) , URL

Arman 1.1k Nov 23, 2022
Form validation and feedback library for Android. Provides .setText for more than just TextView and EditText widgets. Provides easy means to validate with dependencies.

android-formidable-validation Form validation and feedback library for Android. Provides .setText for more than just TextView and EditText widgets. Pr

Linden 147 Nov 20, 2022
An extension of Android's TextView, EditText and Button that let's you use the font of your choice

AnyTextView (deprecated) Note: AnyTextView is no longer being maintained. I recommend replacing AnyTextView with the Calligraphy library instead. Frus

Hans Petter Eide 165 Nov 11, 2022
Simple way to create linked text, such as @username or #hashtag, in Android TextView and EditText

Simple Linkable Text Simple way to create link text, such as @username or #hashtag, in Android TextView and EditText Installation Gradle Add dependenc

Aditya Pradana Sugiarto 76 Nov 29, 2022
Customized and Expandable TextView

Customized and Expandable TextView Simple library to change the Textview as rectangle, circle and square shapes by adding one line of code in xml file

Raja Gopal 62 Sep 22, 2022
An Adapter that allows a RecyclerView to be split into Sections with headers and/or footers. Each Section can have its state controlled individually.

⚠️ Archived: this repository is no longer going to be maintained. SectionedRecyclerViewAdapter An Adapter that allows a RecyclerView to be split into

Gustavo Pagani 1.7k Dec 21, 2022
Animation effects to text, not really textview

HTextView Animation effects with custom font support to TextView see iOS Effects see Flutter Effects Screenshot type gif Scale Evaporate Fall Line Typ

hanks 5.5k Jan 5, 2023
Android's TextView that can expand/collapse like the Google Play's app description

ExpandableTextView ExpandableTextView is an Android library that allows developers to easily create an TextView which can expand/collapse just like th

Manabu S. 4k Dec 28, 2022
A library to show emoji in TextView, EditText (like WhatsApp) for Android

Discontinued This projected is discontinued. Please consider using other alternative, i.e EmojiCompat. Contact me if you want to continue working on a

Hieu Rocker 3.6k Jan 5, 2023
Android experiment showing a sinking TextView

Titanic is an Android experiment reproducing this effect.

Romain Piel 1.8k Dec 15, 2022
A Custom TextView with trim text

ReadMoreTextView A Custom TextView with trim text Download To add the ReadMoreTextView library to your Android Studio project, simply add the followin

Borja B. 1.7k Dec 29, 2022
Advanced Android TextView

Advanced Android TextView Companion app for my Advanced Android TextView talk, demostrating: Animated CompoundDrawable Text shadow Custom font Non-bre

Chiu-Ki Chan 1.2k Dec 9, 2022
A TextView that simulates the effect from the app Secret where the characters fade in/out at different speeds.

SecretTextView A TextView that simulates the effect from the app Secret where the characters fade in/out at different speeds. How To Use Use it just l

Matt Kula 611 Nov 7, 2022
This is based on an open source autosizing textview for Android.

SizeAdjustingTextView This is based on an open source autosizing textview for Android I found a few weeks ago. The initial approach didn't resize mult

Elliott Chenger 255 Dec 29, 2022
Lightweight android library for highlighting sections of a textview, with optional callbacks.

Linker Lightweight android library for highlighting Strings inside of a textview (ignoring case), with optional callbacks. Language: Java MinSDK: 17 J

Josh Gainey 35 Apr 30, 2022