/SmartTextView

Help quickly create super beautiful text

Primary LanguageJava

SmartTextView

Gradle

allprojects{
	repositories{
		...
		maven { url 'https://jitpack.io' }
	}
}

dependencies{
    ...
    implementation 'com.github.novatien:SmartTextView:1.01'
}

Use

Add .xml file

 <com.notin.text.SmartTextView
        android:id="@+id/txt_smart"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:textSize="20sp"
        android:textColor="#000000"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

SmartTextView inherits all the properties and methods of TextView. So I just introduce a few more special methods.

Method Meaning
void textAppend(String text) Appends the text string to the existing string in SmartTextView
void setTextColor(String colorString) Set text font color according to Hex color code
void setTextColor(int color, int startPos, int endPos) Set the color for the substring from position startPos to position endPos-1
void setTextColor(String colorString, int startPos, int endPos) Set the color of the hex code for the substring from position startPos to position endPos-1
void setTextTop(float shiftPercentage,int startPos,int endPos) Brings the substring from startPos to endPos-1 to a higher position
void setStrikethrough() Strikethrough all text
void setStrikethrough(int startPos,int endPos) Strikethrough the substring from the startPos position to the endPos-1 position
void setTypeface(TypefaceSmart type) Bold, italic, and underlined font styles for all text
void setTypeface(TypefaceSmart type,int startPos,int endPos) Bold, italic, and underline typography for substring from startPos position to endPos-1 position

Example

  1. textAppend(String text)
   txt_smart.text="Hello"
   txt_smart.textAppend(" NoTin")

  1. setTextColor(String colorString)
   txt_smart.text="Hello NoTin, Nice to meet you!"
   txt_smart.setTextColor("#FF0000")

  1. setTextColor(int color, int startPos, int endPos)
   txt_smart.text="Hello NoTin, Nice to meet you!"
   txt_smart.setTextColor(Color.GREEN,0,6)

  1. setTextColor(String colorString, int startPos, int endPos)
   txt_smart.text="Hello NoTin, Nice to meet you!"
   txt_smart.setTextColor("#0000EE",0,6)

  1. setTextTop(float shiftPercentage,int startPos,int endPos)
   txt_smart.text="Hello NoTin, Nice to meet you!"
   txt_smart.setTextTop(0.5f,0,5)

  1. setStrikethrough()
   txt_smart.text="Hello NoTin, Nice to meet you!"
   txt_smart.setStrikethrough()

  1. setStrikethrough(int startPos,int endPos)
   txt_smart.text="Hello NoTin, Nice to meet you!"
   txt_smart.setStrikethrough(0,6)

  1. setTypeface(TypefaceSmart type)

TypefaceSmart is an enum with the following values:

  • BOLD
   txt_smart.text="Hello NoTin, Nice to meet you!"
   txt_smart.setTypeface(TypefaceSmart.BOLD)

  • ITALIC
   txt_smart.text="Hello NoTin, Nice to meet you!"
   txt_smart.setTypeface(TypefaceSmart.ITALIC)

  • UNDERLINE
   txt_smart.text="Hello NoTin, Nice to meet you!"
   txt_smart.setTypeface(TypefaceSmart.UNDERLINE)

  • BOLD_ITALIC
   txt_smart.text="Hello NoTin, Nice to meet you!"
   txt_smart.setTypeface(TypefaceSmart.BOLD_ITALIC)

  • BOLD_UNDERLINE
   txt_smart.text="Hello NoTin, Nice to meet you!"
   txt_smart.setTypeface(TypefaceSmart.BOLD_UNDERLINE)

  • ITALIC_UNDERLINE
   txt_smart.text="Hello NoTin, Nice to meet you!"
   txt_smart.setTypeface(TypefaceSmart.ITALIC_UNDERLINE)

  • BOLD_ITALIC_UNDERLINE
   txt_smart.text="Hello NoTin, Nice to meet you!"
   txt_smart.setTypeface(TypefaceSmart.BOLD_ITALIC_UNDERLINE)

  1. setTypeface(TypefaceSmart type,int startPos,int endPos)

TypefaceSmart is an enum with the following values:

  • BOLD
   txt_smart.text="Hello NoTin, Nice to meet you!"
   txt_smart.setTypeface(TypefaceSmart.BOLD,0,6)
  • ITALIC
   txt_smart.text="Hello NoTin, Nice to meet you!"
   txt_smart.setTypeface(TypefaceSmart.ITALIC,0,6)
  • UNDERLINE
   txt_smart.text="Hello NoTin, Nice to meet you!"
   txt_smart.setTypeface(TypefaceSmart.UNDERLINE,0,6)
  • BOLD_ITALIC
   txt_smart.text="Hello NoTin, Nice to meet you!"
   txt_smart.setTypeface(TypefaceSmart.BOLD_ITALIC,0,6)
  • BOLD_UNDERLINE
   txt_smart.text="Hello NoTin, Nice to meet you!"
   txt_smart.setTypeface(TypefaceSmart.BOLD_UNDERLINE,0,6)
  • ITALIC_UNDERLINE
   txt_smart.text="Hello NoTin, Nice to meet you!"
   txt_smart.setTypeface(TypefaceSmart.ITALIC_UNDERLINE,0,6)
  • BOLD_ITALIC_UNDERLINE
   txt_smart.text="Hello NoTin, Nice to meet you!"
   txt_smart.setTypeface(TypefaceSmart.BOLD_ITALIC_UNDERLINE,0,6)