字体变色:
String remark = “”;
Html.fromHtml(remark,Html.FROM_HTML_MODE_COMPACT)
展开收起:
((ItemViewHolder) holder).open_remark_txt.post(new Runnable() {
@Override
public void run() {
if (initState) {
int line = ((ItemViewHolder)holder).open_remark_txt.getLineCount();
seeMore(line, ((ItemViewHolder)holder).open_remark_txt, ((ItemViewHolder)holder).on_off_txt);
}
}
});
/**
* 查看更多
*/
private void seeMore(int line, final TextView contentTxt, final TextView moreTxt) {
if (line >3) {
initState =false;
contentTxt.setMaxLines(initLine);
contentTxt.setEllipsize(TextUtils.TruncateAt.END);
final Drawable img_on = ContextCompat.getDrawable(mContext, R.mipmap.open_icon);
final Drawable img_off = ContextCompat.getDrawable(mContext, R.mipmap.close_icon);
img_on.setBounds(0, 0, img_on.getMinimumWidth(), img_on.getMinimumHeight());
img_off.setBounds(0, 0, img_off.getMinimumWidth(), img_off.getMinimumHeight());
moreTxt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (moreTxt.getText().equals("展开详情")) {
moreTxt.setCompoundDrawables(null, null, img_off, null);
moreTxt.setText("收起详情");
initLine =500;
initState =true;
contentTxt.setMaxLines(500);
}else if (moreTxt.getText().equals("收起详情")) {
moreTxt.setCompoundDrawables(null, null, img_on, null);
moreTxt.setText("展开详情");
initLine =3;
initState =false;
contentTxt.setMaxLines(3);
contentTxt.setEllipsize(TextUtils.TruncateAt.END);
}
}
});
moreTxt.setVisibility(View.VISIBLE);
}else {
initState =true;
moreTxt.setVisibility(View.GONE);
}
}