Android中SpannableString的用法简介
废话少说,具体代码示例如下:
package cn.edu.lzu;
import android.app.Activity; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.text.Spannable; import android.text.SpannableString; import android.text.style.ImageSpan; import android.widget.TextView;
public class TestActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);
TextView textView = (TextView) findViewById(R.id.textview); SpannableString ss = new SpannableString("abcdefghijklmn"); Drawable d = getResources().getDrawable(R.drawable.icon); d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BASELINE); ss.setSpan(span, 0, 6, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); textView.setText(ss);
} }
|
效果图如下:
阅读(6124) | 评论(0) | 转发(0) |