2
我有一个搜索字符串,我需要用粗体样式替换搜索字符串字符到不同的textview字符串。下面 可以编码:字符串匹配字符用粗体不替换搜索字符串
[第一屏幕加载阵列] [1] [阵列搜索字符串] [2] [取代通过搜索字符串中的所有串的TextView] [3]
我!!不希望替换所有的textview字符串,因为我只想从不同的textview字符串位置的粗体特定字符。
![在这里输入的形象描述] [4]
我想这种格式替换风格大胆。
String strlottery =“17659”;
TextView txtS = (TextView) findViewById(R.id.textView5);
TextView txtT = (TextView)findViewById(R.id.textView6);
TextView txt1 = (TextView) findViewById(R.id.textView9);
TextView txt2 = (TextView) findViewById(R.id.textView13);
TextView txt3 = (TextView) findViewById(R.id.textView17);
String str=strlottery.replaceAll("1", "<font size=\"16\" color=\"red\"><b>"+"1"+"</b><</font>");
Log.v("Search", str);
Spanned text = Html.fromHtml(str);
txtf.setText(text);
txtS.setText(text);
txtT.setText(text);
txt1.setText(text);
txt2.setText(text);
txt3.setText(text);
这是我的搜索字符串,我希望在一个ArrayList中搜索这个字符串,然后在ArrayList中获取当我要大胆的性格。 ArrayList字符串是18758,13660,52798,16514,70679。
但是,这是用17659字符串替换所有Textview字符串与匹配字符大胆样式。 1879年搜索字符串,这是取代旧的字符串,但我想DONOT这种类型的替代。我想大胆的风格
感谢您的快速回复。是否适用于动态字符串 – vabhavsingh
Ofcourse ...你需要在这里使用逻辑,..例如 用于字符串.... SpannableString text = new SpannableString(text.getString []); for positions ... text.getLength(); 和这样。 – jay
TextView myText =(TextView)findViewById(R.id.scoreboardtitle); SpannableString text = new SpannableString(strlottery); \t //使 “的Lorem”(字符0至5)红色 text.setSpan(新ForegroundColorSpan(Color.RED),0,4,0); (新的ForegroundColorSpan(Color.rgb(0,255,0)),4,text.length(),0); (新StyleSpan(android.graphics.Typeface.BOLD),0,1,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // here crash report find myText.setText(text,BufferType.SPANNABLE); – vabhavsingh