国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android編程實現TextView部分顏色變動的方法

2020-04-11 11:12:08
字體:
來源:轉載
供稿:網友

本文實例講述了Android編程實現TextView部分顏色變動的方法。分享給大家供大家參考,具體如下:

public class StringHandleExampleActivity extends Activity {  /** Called when the activity is first created. */  private TextView textView;  private String tempStr = "abcd12我的中古zx9yu5!f3,,";  private StringBuffer sb;  private List<Integer> list;  @Override  public void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.main);    sb = new StringBuffer();    list = new ArrayList<Integer>();    textView = (TextView) findViewById(R.id.textView);    for (int i = 0; i < tempStr.length(); i++) {      if (matcherReg(String.valueOf(tempStr.charAt(i)))) {        list.add(i);      }    }    SpannableStringBuilder style=new SpannableStringBuilder(tempStr);    for (int i = 0; i < list.size(); i++) {      System.out.println(list.get(i)+", ");//      style.setSpan(new BackgroundColorSpan(Color.RED),list.get(i),list.get(i)+1,Spannable.SPAN_EXCLUSIVE_INCLUSIVE);   //設置指定位置textview的背景顏色       style.setSpan(new ForegroundColorSpan(Color.RED),list.get(i),list.get(i)+1,Spannable.SPAN_EXCLUSIVE_INCLUSIVE);   //設置指定位置文字的顏色     }    textView.setText(style);   }  private boolean matcherReg(CharSequence c){    String regEx="[^0-9]";      Pattern p = Pattern.compile(regEx);      Matcher m = p.matcher(c.toString());      if (m.matches()) {      return false;    }    return true;  }}

希望本文所述對大家Android程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 广昌县| 剑河县| 阿图什市| 巢湖市| 桃源县| 漠河县| 久治县| 东宁县| 三原县| 错那县| 襄汾县| 伊宁县| 崇信县| 乌苏市| 龙井市| 汝阳县| 城口县| 灵宝市| 道真| 高密市| 府谷县| 衡南县| 巴林左旗| 叙永县| 留坝县| 应用必备| 合水县| 巴林左旗| 邵东县| 德阳市| 临洮县| 通山县| 澄江县| 龙州县| 那曲县| 卫辉市| 盐津县| 安康市| 浦北县| 哈巴河县| 乐亭县|