Android TextView实现不同字体颜色并添加点击事件

来源:互联网 发布:苹果发布会 mac pro 编辑:程序博客网 时间:2024/05/29 09:03

SpannableStringBuilder span = new SpannableStringBuilder((TextUtils.isEmpty(dn.getCreaterName()) ? "" : dn.getCreaterName())+":"+dd);                    span.setSpan(new ClickableSpan() {                        @Override                        public void updateDrawState(TextPaint ds) {                            ds.setUnderlineText(false); //去掉下划线                        }                        @Override                        public void onClick(View widget) {//你需要执行的点击事件                            if (dn.createType == 1)                                ENavigate.startRelationHomeActivity(mContext, dn.getCreaterId() + "", true, 1);                            else                                ENavigate.startOrgMyHomePageActivityByOrgId(mContext, dn.getCreaterId());                        }                    },0,dn.getCreaterName().length()+1,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);                    ForegroundColorSpan fspan = new ForegroundColorSpan(getActivity().getResources().getColor(R.color.text_flow_more));                    span.setSpan(fspan,0,dn.getCreaterName().length()+1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);                    holder.contentTv.setText(span);                    holder.contentTv.setMovementMethod(LinkMovementClickMethod.getInstance());
上面的图是我盗用别的地方的图,下面代码是我实现的方法,我需要把dn.getCreaterName()显示个颜色并且还可以点击,updateDrawState方法不重写会有下划线


阅读全文
0 0