android layout en,docs/Android/customLayoutEn.md · 无厘头/aurora-imui - Gitee.com

## Customize widget style

[中文文档](./customLayout.md)

If you want to totally customize your widget, you can define custom ViewHolder and layout.

This document will show you how to do it.

### Step

Customize your widget style only need three steps.

#### Step one: create custom message item layout

Create xml layout file, you can refer MessageList's message item layout.

#### Step two:Create ViewHolder extends BaseMessageViewHolder and implements DefaultMessageViewHolder

The custom ViewHolder's constructor **must** have two types of parameter: View type and boolean type. For example:

```

public class TxtViewHolder

extends BaseMessageViewHolder

implements MsgListAdapter.DefaultMessageViewHolder {

// Notice here

public TxtViewHolder(View itemView, boolean isSender) {

super(itemView);

...

}

@Override

public void onBind(final MESSAGE message) {

...

}

@Override

public void applyStyle(MessageListStyle style) {

...

}

```

#### Step three: Use HoldersConfig object to set custom ViewHolder and layout

Remember there several kinds of message: text, photo, voice, video, so you need in place all of them,

otherwise, will use default style.

```

MsgListAdapter.HoldersConfig holdersConfig = new MsgListAdapter.HoldersConfig();

// First parameter is custom ViewHolder class,second one is resource id of custom layout.

holdersConfig.setSenderTxtMsg(CustomViewHolder.class, layoutRes);

holdersConfig.setReceiverTxtMsg(CustomViewHolder.class, layoutRes);

holdersConfig.setSendPhotoMsg(CustomViewHolder.class, layoutRes);

...

```

That's all! Please try it by yourself!

一键复制

编辑

Web IDE

原始数据

按行查看

历史

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值