我需要文本视图,其中第一个字母大写,就像照片上一样。实现这一目标的最佳库或解决方案是什么?
问问题
250 次
2 回答
1
您可以SpannableString
在不使用任何库的情况下使用。
String title = "This is a very good thing. You should try with that and suggest to others";
final SpannableString spannableString = new SpannableString(title);
int position = 0;
for (int i = 0, ei = title.length(); i < ei; i++) {
char c = title.charAt(i);
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')) {
position = i;
break;
}
}
spannableString.setSpan(new RelativeSizeSpan(2.0f), position, position + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
txt.setText(spannableString, TextView.BufferType.SPANNABLE);
title
您可以在变量中使用您的文本。
于 2017-05-10T11:42:51.803 回答
1
1.在app/build.gradle中添加如下依赖
compile 'com.github.rpradal.lettrine:lettrine:release_number'
2.使用LettrineTextView
<com.github.rpradal.lettrine.LettrineTextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
app:lettrine_textColor="@android:color/holo_red_dark"
app:lettrine_text="Lorem ipsum"
app:lettrine_lettrineSize="3"
app:lettrine_textSize="14sp" />
如需更多帮助,请点击此链接
结果将如下:
于 2017-05-10T12:10:33.123 回答