एक तरह से यह करने के लिए TypefaceSpan विस्तार करने के लिए है:
import android.graphics.Paint;
import android.graphics.Typeface;
import android.text.TextPaint;
import android.text.style.TypefaceSpan;
public class CustomTypefaceSpan extends TypefaceSpan {
private final Typeface newType;
public CustomTypefaceSpan(String family, Typeface type) {
super(family);
newType = type;
}
@Override
public void updateDrawState(TextPaint ds) {
applyCustomTypeFace(ds, newType);
}
@Override
public void updateMeasureState(TextPaint paint) {
applyCustomTypeFace(paint, newType);
}
private static void applyCustomTypeFace(Paint paint, Typeface tf) {
int oldStyle;
Typeface old = paint.getTypeface();
if (old == null) {
oldStyle = 0;
} else {
oldStyle = old.getStyle();
}
int fake = oldStyle & ~tf.getStyle();
if ((fake & Typeface.BOLD) != 0) {
paint.setFakeBoldText(true);
}
if ((fake & Typeface.ITALIC) != 0) {
paint.setTextSkewX(-0.25f);
}
paint.setTypeface(tf);
}
}
फिर जब आप दो अलग अलग टाइपफेस का उपयोग करना चाहते फोन:
String firstWord = "first ";
String secondWord = "second";
// Create a new spannable with the two strings
Spannable spannable = new SpannableString(firstWord+secondWord);
// Set the custom typeface to span over a section of the spannable object
spannable.setSpan(new CustomTypefaceSpan("sans-serif",CUSTOM_TYPEFACE), 0, firstWord.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
spannable.setSpan(new CustomTypefaceSpan("sans-serif",SECOND_CUSTOM_TYPEFACE), firstWord.length(), firstWord.length() + secondWord.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
// Set the text of a textView with the spannable object
textView.setText(spannable);
, इसलिए आप विभिन्न fontstyles साथ दो अलग अलग TextView उपयोग नहीं कर सकते करने के लिए सेट कर रहे हैं। –
@ सेंथिलएमजी आप इस प्रश्न में संदर्भ लिंक पर इसका कारण देख सकते हैं।यह टेक्स्ट को प्रारूपित नहीं करेगा क्योंकि इसकी आवश्यकता – rizzz86
है, मुझे लगता है कि रीजिक्स का उपयोग करके पूर्ण स्ट्रिंग को दो में विभाजित करने का अनुमान है: और विभिन्न टेक्स्टव्यू पर सेट करें उदाहरण के लिए: स्ट्रिंग टेक्स्ट = एएएए: बीबीबीबीबी, स्ट्रिंग [] splitText = text.split (":"); tv1.setText (splitText [0]); tv2.setText (splitText [1]); –