最近项目中用到腾讯的即时通讯(云通信),做到C2C聊天这块。需要将聊天界面的己方和对方的默认头像替换掉。
具体操作如下:
1:对ChatAdapter.java类新增
private TIMUserProfile mMySelfProfile;
private TIMUserProfile mMyFriendProfile; 成员变量。通过get或者set方式注入。
对ChatAdapter.ViewHolder也新增
public TIMUserProfile mMySelfProfile;
public TIMUserProfile mMyFriendProfile; 成员变量.
通过ChatAdapter对ChatAdapter.ViewHolder的成员变量赋值;
2:对Message类的子类的showMessage(ChatAdapter.ViewHolder viewHolder, Context context)方法,
已TextMessage为例,其他子类依次类推:
@Override
public void showMessage(ChatAdapter.ViewHolder viewHolder, Context context) {
clearView(viewHolder);
if (checkRevoke(viewHolder)) return;
boolean hasText = false;
TextView tv = new TextView(MyApplication.getContext());
tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
tv.setTextColor(MyApplication.getContext().getResources().getColor(isSelf() ? R.color.color_666666 : R.color.color_666666));
List<TIMElem> elems = new ArrayList<>();
for (int i = 0; i < message.getElementCount(); ++i){