Is it possible to set different TextSize for different parts of the content of a given Textview using XML in android ?
            Asked
            
        
        
            Active
            
        
            Viewed 1,379 times
        
    0
            
            
         
    
    
        Raghunandan
        
- 132,755
- 26
- 225
- 256
 
    
    
        user3293494
        
- 609
- 1
- 9
- 21
- 
                    You can do that in java code. Misread the question at first and posted a alternative solution – Raghunandan May 14 '14 at 11:42
- 
                    through xml, I don't think it's possible. But in Java code you can achieve it using Html tags or through `SpannableString`. – Spring Breaker May 14 '14 at 11:44
- 
                    Your question isn't clear. What does "...using XML in android ?" mean exactly? – Squonk May 14 '14 at 11:44
2 Answers
2
            
            
        Programatically but not using XML you could achieve it using setSpan
For 10 Characters word with first 5 chars has fontsize 12 and last 5 chars has 16.
 Textview myTextView = (TextView)findViewById(R.id.textview); SpannableString
 text = new SpannableString(myString);
 text.setSpan(new TextAppearanceSpan(null, 0, 12, null, null),0,5,
 Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 
 text.setSpan(new TextAppearanceSpan(null, 0, 16, null, null),6,10,
 Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
 myTextView.setText(text, TextView.BufferType.SPANNABLE);
 
    
    
        Vinayak Bevinakatti
        
- 40,205
- 25
- 108
- 139
 
    