我们都十分熟悉TextView的使用,但是还有一个不错的控件CBAlignTextView
使用步骤:
- build.gradel加入dependencies
compile ‘me.codeboy.android:align-text-view:2.3.0’ xml中
<me.codeboy.android.aligntextview.CBAlignTextView
android:id="@+id/cbAlignTv"
android:textIsSelectable="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
特点:
- 支持复制
- 排版效果较好
注意:
由于Android L(5.0)之后对中文的版本进行了变化,造成不能由中文标点作为行首,所以为了能够使CBAlignTextView看起来更加工整,建议将中文符号用英文符号替换(默认不转换)
解决:
- 使用转化函数转化标点符号:
CBAlignTextViewUtil.replacePunctuation("");
源码:
public static String replacePunctuation(String text) {
text = text.replace(',', ',').replace('。', '.').replace('【', '[').replace('】', ']')
.replace('?', '?').replace('!', '!').replace('(', '(').replace(')', ')').replace
('“', '"').replace('”', '"');
return text;
}
根据自己的需求使用