Android spanned SPAN_INCLUSIVE_INCLUSIVE SPAN_EXCLUSIVE_EXCLUSIVE
以前一直不懂Spanned属性 SPAN_EXCLUSIVE_EXCLUSIVE, SPAN_EXCLUSIVE_EXCLUSIVE。
下面我以一个demo展示其意思
在 activity_main.xml activity_main.xml
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我爱中国人" />
在Java代码
mTxtView = (EditText) findViewById(R.id.test);
SpannableString sp = new SpannableString(mTxtView.getText());
sp.setSpan(new ForegroundColorSpan(Color.RED), 1, 3,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
mTxtView.setText(sp);
其结果是“我爱中国人” , 在EditText “爱”前、“中”后 插入文字时时 ,字不会显示红色
如果设置“SPAN_INCLUSIVE_INCLUSIVE”, 在“爱”前,“中”后插入文字时,字会变红色
更多相关文章
- Android之TextView------文字底部或者中间加横线
- android edittext获取选中文字
- android 分享文字到其他应用程序
- Android Shader应用开发之霓虹闪烁文字效果
- Android 开发 Tip 6 -- Spinner 文字 & icon 居中显示
- Android 如何实现带滚动条的TextView,在更新文字时自动滚动到最后
- [Android1.5]标签TabHost图片文字覆盖的问题