textview设置不同字体大小

 

<style name="style0">
	    <item name="android:textSize">19dip</item>
	    <item name="android:textColor">@color/color1</item>
        </style>
	
	<style name="style1">
	    <item name="android:textSize">23dip</item>
	    <item name="android:textColor">@color/color2</item>
	    <item name="android:textStyle">italic</item>
	</style>

  

 

<span style="white-space:pre">		</span>mTextView = (TextView)findViewById(R.id.test);
		
		 SpannableString styledText = new SpannableString("亲爱的小宝,你好");
		 styledText.setSpan(new TextAppearanceSpan(this, R.style.style0), 0, 3, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
		 styledText.setSpan(new TextAppearanceSpan(this, R.style.style1), 3, 5, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
		
		mTextView.setText(styledText, TextView.BufferType.SPANNABLE);

  

posted @ 2017-01-16 17:23  wikiki  阅读(576)  评论(0编辑  收藏  举报