Android 快速拨号 字体高亮

网上查阅关于字体高亮一般有两种做法
1.
String str="adsjoiasdjpaisdjpaidj";  
/** Called when the activity is first created. */  
     @Override  
     public void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.laychangerout.main);  
        textview=(TextView)findViewById(R.id.textview);  
        SpannableStringBuilder style=new SpannableStringBuilder(str);  
        style.setSpan(new    ForegroundColorSpan(Color.RED),3,8,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 
        textview.setText(style);  changer  
       }  

2.
   String source = "这只是一个测试字符串,测试<b>黑体字</b>、<i>斜体字</i>、<u>下划线</u>、<font color='red'>红色字</font>的显示。";  
   textView.setText(Html.fromHtml(source));  

做快速查询号码的时候可能是对某一个字符串里某一个数字都需要高亮!那么可以用着种转成HTML代码的方式在画图前吧对应数字替代!
public View getView(int position, View convertView, ViewGroup parent) {
			if (convertView == null) {
				LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
				convertView = inflater.inflate(R.layout.dialer_contacts_item,
						parent, false);
			}
			final ImageView contactPhoto = (ImageView) convertView
					.findViewById(R.id.photo);
			final TextView contactName = (TextView) convertView
					.findViewById(R.id.contactName);
			final TextView contactNumber = (TextView) convertView
					.findViewById(R.id.contactNumber);
			final ContactEntity ce = getItem(position);
			Bitmap headMap = ce.contact_phone_bmp;
			if (null != headMap) {
				contactPhoto.setImageBitmap(headMap);
			} else {
				contactPhoto.setImageResource(R.drawable.ic_contact_picture);
			}
			contactName.setText(ce.contacts_display_name);
			[color=red]if (!"".equals(searchStr)) {
				String phone_number = ce.contacts_phone_number
						.replaceAll(searchStr, "<font color='red'>" + searchStr
								+ "</font>");
				contactNumber.setText(Html.fromHtml(phone_number));
			} else {
				contactNumber.setText(ce.contacts_phone_number);
			}[/color]
			return convertView;
		}
上一篇:oracle的nvl和sql server的isnull


下一篇:Android EditText值在intent中获取编辑后切屏会导致编辑信息无法保存的BUG