無圖無真相,o(∩_∩)o哈哈~
這種效果乙個textview就可以搞定,多種字型樣式,多種顏色,多種字型大小
廢話不多說,直接上**:
/**
*@date on 2019/4/25
*@author kelina
*@describe 自定義textview,實現同個textview使用多種字型樣式
*/private listcustomtypefacespans = new arraylist<>();
private listspans= new arraylist<>();
public multtypefacetextview(context context)
public multtypefacetextview(context context, @nullable attributeset attrs)
public multtypefacetextview(context context, @nullable attributeset attrs, int defstyleattr)
/*** 設定字型樣式
* @param customtypefacespan typeface、文字縮放大小,顏色id
* @param span 需要修改字型樣式的文字
*/public void settypefacespan(customtypefacespan customtypefacespan,string span)
@override
public void settext(charsequence text, buffertype type) {
int index;
if(!textutils.isempty(text) && spans!=null){
spannablestringbuilder ssb = new spannablestringbuilder(text);
for(int i=0,length = spans.size();i呼叫方法:
string s="一生一世:1314,我愛你:520,氣死氣死你:74740";
multtypefacetextview multtypefacetextviewid = findviewbyid(r.id.multtypefacetextviewid);
multtypefacetextviewid.settypefacespan(new customtypefacespan(s, typeface.createfromasset(getassets(), "go.otf"),1.8f,getresources().getcolor(r.color.coloraccent)),"1314");
multtypefacetextviewid.settypefacespan(new customtypefacespan(s,typeface.createfromasset(getassets(), "font.ttf"),1.5f,getresources().getcolor(r.color.coloraccent)),"520");
multtypefacetextviewid.settypefacespan(new customtypefacespan(s,typeface.createfromasset(getassets(), "tt1018m_.ttf"),1.0f,getresources().getcolor(r.color.coloraccent)),"74740");
multtypefacetextviewid.settext(s);
TextView設定字型樣式
packagecom.zhou.activity import importandroid.graphics.color importandroid.os.bundle importandroid.text.spannable importandroid.text.spannablestring i...
TextView設定個別字型樣式
隨筆 139 文章 1 1 spannablestring msp new spannablestring 測試 xm 更換當前號碼將從手機傳送一條普通簡訊進行驗證 2 msp.setspan new foregroundcolorspan color.blue 2,xm.length 2,span...
TextView設定個別字型樣式
1 spannablestring msp new spannablestring 測試 xm 更換當前號碼將從手機傳送一條普通簡訊進行驗證 2 msp.setspan new foregroundcolorspan color.blue 2,xm.length 2,spanned.span exc...