A simpler way to style your TextViews

Overview

BabushkaText

BabushkaText is a custom TextView which lets you customize the styling of parts of your text via Spannables, but without the hassle of having to deal directly with Spannable themselves.

  • Create complex style structures for your text without having to add multiple TextViews to your view hierarchy.
  • Eliminate setSpan(Object what, int start, int end, int flags) calls by using more convenient methods such as .style(Typeface.BOLD), .superscript() and others.

What can I do with BabushkaText?

Examples of different styles. Each one is a single TextView.

Logo

Example

Generate the following style:

NewY York

With the code below:

        BabushkaText babushka = (BabushkaText)findViewById(R.id.babushka_text);

        // Add the first piece "Central Park"
        babushka.addPiece(new BabushkaText.Piece.Builder("Central Park, NY\n")
                .textColor(Color.parseColor("#414141"))
                .build());

        // Add the second piece "1.2 mi"
        babushka.addPiece(new BabushkaText.Piece.Builder("1.2 mi ")
                .textColor(Color.parseColor("#0081E2"))
                .textSizeRelative(0.9f)
                .build());

        // Add the third piece "from here"
        babushka.addPiece(new BabushkaText.Piece.Builder("from here")
                .textColor(Color.parseColor("#969696"))
                .textSizeRelative(0.9f)
                .build());

        // Display the final, styled text
        babushka.display();

What kind of styles can I add?

Right now you can customize the style of your text by using the following methods, which internally get converted to the corresponding Spannables

Babushka Method Internal Span
textSize AbsoluteSizeSpan
textColor ForegroundColorSpan
textSizeRelative RelativeSizeSpan
backgroundColor BackgroundColorSpan
style StyleSpan
underline UnderlineSpan
strike StrikethroughSpan
superscript SuperscriptSpan
subscript SubscriptSpan

What else can I do?

Once you've created and displayed your BabushkaText, you can modify the text contents of each Piece individually. For example, if we want to change the 1.2 mi from the above example into 1.9 km, we could do the following:

// grab the Piece at position 1
Piece piece = babushka.getPiece(1);

// modify it's text
piece.setText("1.9 km ");

// you must always call display after you alter a Piece's text
babushka.display();

Download

BabushkaText is a single Java file, so you can simply download it and reference it in your project.

Download BabushkaText.java here: BabushkaText

Or if you prefer, you can simply download the JAR

Contact Me

If you find any bugs or have a problem while using this library, please open an issue in this repo (or a pull request :)).

License

Copyright 2014 Henrique Boregio

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
  • How to use it in xml eclypse file ?

    How to use it in xml eclypse file ?

    Hi, I was looking for your amazing Babushka Text, I implemented it on my java class file, all ok, but I need to link it was Resource (you said : BabushkaText babushka = (BabushkaText)findViewById(R.id.babushka_text);), and when I do it (for me : BabushkaText text = (BabushkaText)findViewById(R.id.text_preview);) where text_preview is a TextView, there's an error (normal :D) ! So, how could I implement the Babushka on XML file ? Thank you, and, have a good day ! PS : My text_preview on XML is :+1:

    opened by OwnHno 3
  • set text color has no effect

    set text color has no effect

    For example:

    bt.addPiece(new BabushkaText.Piece.Builder("please\n")
                .style(Typeface.BOLD)
                .textSize(35)
                .build());
    bt.addPiece(new BabushkaText.Piece.Builder("change textcolor")
                .textSize(20)
                .build());
    bt.display();
    

    I get textview with black text colour (default color) Then I call

    bt.setTextColor(getResources().getColor(R.color.white));
    

    And textColor remains black. I understand what there is no built-in ability to change spannable text colour on the fly, but it's would be very helpful function.

    enhancement 
    opened by IlyaEremin 1
  • List Adapter problem

    List Adapter problem

    Hi Thank for your effort. I have a question about this class.

    When i use this in the list view..

    AirPortName.addPiece(new BabushkaText.Piece.Builder(listData.get(position).getAirPortName()) .backgroundColor(Color.parseColor("#DFF1FE")) .textColor(Color.parseColor("#073680")) .style(Typeface.BOLD) .build()); AirPortName.display();

    this is my code.

    But problem is ..duplicated the text when i scroll up and down.

    so..I try this code

    AirPortName = (BabushkaText)row.findViewById(R.id.title); AirPortName.reset(); AirPortName.addPiece(new BabushkaText.Piece.Builder(listData.get(position).getAirPortName()) .backgroundColor(Color.parseColor("#DFF1FE")) .textColor(Color.parseColor("#073680")) .style(Typeface.BOLD) .build()); AirPortName.display();

    Use this... AirPortName.reset();

    is it right?

    Thanks a lot.

    opened by sangrime 1
  • i have a problem..

    i have a problem..

    i want to use babushktext, so i copy .java code. but i have a problem with my code... I'd really appreciate it if you help me ------------solve it kkk.... how do i delete this post-------- 2017-04-01_13-01-13

    opened by hyekie 1
  • 修改了 DEFAULT_ABSOLUTE_TEXT_SIZE 静态变态对别的textview的影响

    修改了 DEFAULT_ABSOLUTE_TEXT_SIZE 静态变态对别的textview的影响

    if (aPiece.textSize==0)

    •    {
      
    •        aPiece.textSize = DEFAULT_ABSOLUTE_TEXT_SIZE;
      
    •    }
      
    •    finalString.setSpan(new AbsoluteSizeSpan(aPiece.textSize), start, end, Spannable
      
    •            .SPAN_EXCLUSIVE_EXCLUSIVE);
      
    opened by Aarthas 0
Owner
Henrique Boregio
CTO @ Primephonic
Henrique Boregio
An easy, flexible way to add a shimmering effect to any view in an Android app.

Shimmer for Android Shimmer is an Android library that provides an easy way to add a shimmer effect to any view in your Android app. It is useful as a

Facebook 5.1k Dec 31, 2022
A little animation framework which could help you to show message in a nice looking way

TextSurface A little animation framework which could help you to show message in a nice looking way. Usage Create TextSurface instance or add it in yo

Eugene Levenetc 2.3k Dec 25, 2022
A simpler way to style your TextViews

BabushkaText BabushkaText is a custom TextView which lets you customize the styling of parts of your text via Spannables, but without the hassle of ha

Henrique Boregio 752 Dec 29, 2022
A simpler way to style your TextViews

BabushkaText BabushkaText is a custom TextView which lets you customize the styling of parts of your text via Spannables, but without the hassle of ha

Henrique Boregio 753 Jun 7, 2022
Android Library that provide simpler way to achieve modularity

ToyBricks 中文文档 ToyBricks简介以及原理分析 ToyBricks用户手册 Introduction Android Library that provide simpler way to achieve modularity. Compile System requirement

null 33 Nov 14, 2022
Binding your extras more easier, more simpler for your Android project

Ktan Ktan make your intent / arguments more easier and readable. And most important, will help you bind all extras for your activity / fragment. And a

Ade Fruandta 3 Jan 7, 2023
Custom font library for android | Library to change/add font of Entire Android Application at once without wasting your time - TextViews, EditText, Buttons, Views etc.,

AppFontChanger In a Single shot change font of Entire Android Application - TextViews, EditText, Buttons, Views etc., Kindly use the following links t

Prabhakar Thota 48 Aug 10, 2022
[ACTIVE] Simple Stack, a backstack library / navigation framework for simpler navigation and state management (for fragments, views, or whatevers).

Simple Stack Why do I want this? To make navigation to another screen as simple as backstack.goTo(SomeScreen()), and going back as simple as backstack

Gabor Varadi 1.3k Jan 2, 2023
A more lightweight and simpler to use MVVM architecture for Android.

A more lightweight and simpler to use MVVM architecture for Android, Data and views are two-way bound.

fangbing chen 7 Jul 5, 2022
****. Use the native and support library variants instead - https://developer.android.com/guide/topics/ui/look-and-feel/fonts-in-xml.html. An android library that makes it easy to add custom fonts to edittexts and textviews

Add to your project Add this line to your dependencies in build.gradle compile 'in.workarounds.typography:typography:0.0.8' Using the views There are

Workarounds 43 Nov 6, 2021
A tool that facilitates working with Spans on TextViews or any extension of them (EditTexts, Buttons...).

AwesomeText Working with Spans is ugly and difficult to manage, it's like working with a goblin of Moria. Don't understand the Spans? With AwesomeText

José Manuel Pereira García 674 Nov 27, 2022
🪄 This is an animation library with an increasing number of TextViews

CountNumberEvent ?? This is an animation library with an increasing number of TextViews Demo Setup Add it in your root build.gradle at the end of repo

박상선 5 Feb 17, 2022
FadeOutParticle is an animation for disappearing views like TextViews

FadeOutParticle is an animation for disappearing views like TextViews

Hooman Mohammadi 50 Dec 28, 2022
iOS style scroll wheel (style similar to UIPickerView)

WheelPicker iOS-style scroll wheel picker Read this in other languages: Feature Day / Night Mode Support Customizable style Support circular scro

Tian Yiyan 21 Dec 30, 2022
An easy way to customize your log in Android,including output to console, writing log to file in high performance way and so on

EasyLog An easy way to customize your log in Android,including output to console, writing log to file in high performance way and so on. 1. Initializa

Taylor 40 Dec 8, 2022
This is an Image slider with swipes, Here we used Volley to Image load URL's from JSON! Here we make it very easy way to load images from Internet and We customized the description font style(OpenSans).

ImageSliderWithSwipes This is an Image slider with swipes, Here we used Volley to load URL's from JSON! Here we make it very easy way to load images f

Prabhakar Thota 44 May 31, 2021
Make your native android Dialog Fancy and Gify. A library that takes the standard Android Dialog to the next level with a variety of styling options and Gif's. Style your dialog from code.

FancyGifDialog-Android Prerequisites Add this in your root build.gradle file (not your module build.gradle file): allprojects { repositories { ...

Shashank Singhal 522 Jan 2, 2023
Make your native android Toasts Fancy. A library that takes the standard Android toast to the next level with a variety of styling options. Style your toast from code.

FancyToast-Android Prerequisites Add this in your root build.gradle file (not your module build.gradle file): allprojects { repositories { ... ma

Shashank Singhal 1.2k Dec 26, 2022
Make your native android Dialog Fancy. A library that takes the standard Android Dialog to the next level with a variety of styling options. Style your dialog from code.

FancyAlertDialog-Android Prerequisites Add this in your root build.gradle file (not your module build.gradle file): allprojects { repositories { ..

Shashank Singhal 350 Dec 9, 2022
Put some bubble in your tabs and give your apps a supa fresh style !

BubbleTab Put some bubble in your tabs and give your apps a supa fresh style ! Usage Add a BubbleTab with your icons on the layout.xml Customisable pa

Florent CHAMPIGNY 535 Nov 18, 2022