views:

356

answers:

1

I have a button in my Android project that contains two rows with text to the left, and one drawable on the right side. This works perfectly with this code:

<Button 
  android:text="Call History" 
  android:id="@+id/accountCallLogButton" 
  android:layout_width="fill_parent" 
  android:layout_height="wrap_content"
  android:drawableRight="@drawable/arrow"
  android:padding="10sp" 
  android:background="@drawable/buttconfig" 
  android:gravity="left|center_vertical">
 </Button>

String resource:

<string name="addCreditButtonText">Add Credit\nOpens in browser</string>

My problem here is that in the second Line of the String resource, I want to have a smaller font size and italic font.
How can I solve this?

+2  A: 

Step #1: Put HTML markup in your string resource that describes what you want (italic, smaller font)

Step #2: Use Html.fromHtml() to convert that string resource to a SpannedString

Step #3: Call setText() on your Button with that SpannedString

CommonsWare