当前位置: 代码迷 >> Android >> Android 高速拨号 字体高亮
  详细解决方案

Android 高速拨号 字体高亮

热度:77   发布时间:2016-05-01 13:48:18.0
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;		}
  相关解决方案