如果文本超过 4 行,我想显示阅读更多或继续阅读。怎么办,我尝试了一些方法,但不起作用;
if (myHolder.userTexts.getMaxLines()==4){
myHolder.showMore.setVisibility(View.VISIBLE);
} else {
myHolder.showMore.setVisibility(View.GONE);
}
如果你想看看我的布局;
<TextView
android:id="@+id/showMore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:text="@string/conti_read"
android:visibility="gone"
android:textStyle="bold"
android:gravity="center"
android:textSize="14sp" />
最佳答案
您可以使用此代码
if (text.length() > length) {
String sub = text.substring(0, length);
textView.setText(Html.fromHtml(sub + "<font color='#F39322'> " + seeMore + "</font>"));
textView.setOnClickListener(view -> {
if (textView.getText().equals(text)) {
textView.setText(Html.fromHtml(sub + "<font color='#F39322'> " + seeMore + "</font>"));
} else {
textView.setText(text);
}
});
} else {
textView.setText(text);
}
如果这对您有用,请投票给我
关于java - 如果文本的最大行数超过 4 条,如何显示阅读更多文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58278665/