Simple SpannableString Builder.
Add maven jitpack.io and dependencies in build.gradle (Project) :
// build.gradle projectallprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
// build.gradle app/moduledependencies {
...
implementation 'com.github.gzeinnumer:EasySpannableText:version'
}intsizeInDp = 21;
intcolor = ContextCompat.getColor(this, R.color.purple_500);
CharSequencesequence = newSpannableBuilder(getApplicationContext())
.text(Typeface.NORMAL,"text\n")
.textColor(Typeface.BOLD,"textColor\n", color)
.textSize(Typeface.ITALIC,"textSize\n", sizeInDp)
.textSizeColor(Typeface.BOLD_ITALIC,"textSizeColor\n", sizeInDp, color)
.build();
textView.setText(sequence); //or textView.setText(sequence, TextView.BufferType.SPANNABLE);Typeface optional value
Typeface.NORMALTypeface.BOLDTypeface.ITALICTypeface.BOLD_ITALIC
Preview :
add 1 parameter in function .text(),.textColor(),.textSize(),.textSizeColor(). and add setMovementMethod() after setText(). Example.
intsizeInDp = 21;
intcolor = ContextCompat.getColor(this, R.color.purple_500);
CharSequencesequence = newSpannableBuilder(getApplicationContext())
.text(Typeface.NORMAL, "text\n", newSpannableCallBack() {
@OverridepublicvoidonClick() {
Toasttoast = Toast.makeText(MainActivity.this, "Tekan 1", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.TOP, 0, 0);
toast.show();
}
})
.textColor(Typeface.BOLD, "textColor\n", color, newSpannableCallBack() { ... })
.textSize(Typeface.ITALIC, "textSize\n", sizeInDp, newSpannableCallBack() { ... })
.textSizeColor(Typeface.BOLD_ITALIC, "textSizeColor\n", sizeInDp, color, newSpannableCallBack() { ... })
.build();
textView.setText(sequence); //or textView.setText(sequence, TextView.BufferType.SPANNABLE);textView.setMovementMethod(LinkMovementMethod.getInstance());Preview :
Without OnClick & With OnClick
- 1.0.0
- First Release
- 1.0.1
- Value in DP
You can sent your constibution to branchopen-pull.
Fore More All My Library
Copyright 2021 M. Fadli Zein

