• Stars
    star
    778
  • Rank 58,431 (Top 2 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 11 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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.

More Repositories

1

Android-AppMsg

In-layout notifications. Based on Toast notifications and article by Cyril Mottier (http://android.cyrilmottier.com/?p=773).
Java
1,370
star
2

Android-ProgressFragment

Implementation of the fragment with the ability to display indeterminate progress indicator when you are waiting for the initial data.
Java
808
star
3

SideNavigation

Implementation of "Side Navigation" or "Fly-in app menu" pattern for Android (based on Google+ app)
Java
318
star
4

Android-Icon-Fonts

Material and Holo iconic fonts.
HTML
222
star
5

Print

A lightweight Android library for use iconic fonts.
Java
205
star
6

Android-CollapsibleSearchMenu

Implementation of the SearchView is compatible with Android below 3.0. This library allows developers to easily integrate search menuItem in an Android application.
Java
118
star
7

SpySMS

Interceptor sms for android
Java
80
star
8

MockGPS

The application to emulate the location
Java
16
star
9

Android-AppMsg-Gradle-Sample

The sample project that uses Android-AppMsg via Gradle.
Shell
12
star
10

RecipeBook

Recipe Book for Android
Java
12
star
11

Android-JSONCompare

Comparison of JSON parsers performance on Android
Java
12
star
12

Metro

Modern subway maps of Moscow and Saint Petersburg.
Java
11
star
13

android-without-fragments

Demo for presentation "Life without Fragments" #MBLTdev16
Kotlin
9
star
14

CookApp

Android application of cooking
Java
8
star
15

Android-ProgressFragment-Gradle-Sample

The sample project that uses Android-ProgressFragment via Gradle.
Java
7
star
16

Steganography

Steganography is the art and science of writing hidden messages in such a way that no one, apart from the sender and intended recipient, suspects the existence of the message, a form of security through obscurity.
Java
6
star
17

DoubleBackExample

Example: double back to exit
Java
4
star
18

GeocoderExample

Example of a geocoder to Android
Java
3
star
19

johnkil

1
star
20

VK-Music-Downloader

The application to download music from the social network Vkontakte.
1
star