下文将向您展示如何设置会话列表界面自定义选项及其效果。
设置会话列表、cell 背景色
API 作用:设置会话列表、cell、置顶 cell 的背景色。
API 原型:
// TUIConversationConfigClassic.java/*** Background color of conversation list.*/public static void setListBackground(Drawable listBackground)/*** Background color of cell in conversation list.* This configuration takes effect in all cells.*/public static void setCellBackground(Drawable cellBackground)/*** Background color of pinned cell in conversation list.* This configuration takes effect in all pinned cells.*/public static void setPinnedCellBackground(Drawable pinnedCellBackground)
示例代码:
// When to call: Before initializing conversation list.TUIConversationConfigClassic.setListBackground(new ColorDrawable(0xFFFFFFF0)); TUIConversationConfigClassic.setCellBackground(new ColorDrawable(0xFFF0FFF0)); TUIConversationConfigClassic.setPinnedCellBackground(new ColorDrawable(0xFFE1FFFF));
设置效果:
设置背景色 | 默认 |
| |
设置会话列表 cell 字体
API 作用:设置会话列表 cell 上的标题、副标题、时间文字的字体。针对所有 cell 生效。
API 原型:
// TUIConversationConfigClassic.java/*** Font of title label of cell in conversation list.* This configuration takes effect in all cells.*/public static void setCellTitleLabelFontSize(int cellTitleLabelFontSize)/*** Font of subtitle label of cell in conversation list.* This configuration takes effect in all cells.*/public static void setCellSubtitleLabelFontSize(int cellSubtitleLabelFontSize)/*** Font of time label of cell in conversation list.* This configuration takes effect in all cells.*/public static void setCellTimeLabelFontSize(int cellTimeLabelFontSize)
示例代码:
// When to call: Before initializing conversation list.TUIConversationConfigClassic.setCellTitleLabelFontSize(18);TUIConversationConfigClassic.setCellSubtitleLabelFontSize(14);TUIConversationConfigClassic.setCellTimeLabelFontSize(16);
设置效果:
设置字体 | 默认 |
| |
展示未读红点
API 作用:展示 cell 上的未读消息红点 icon。针对所有 cell 生效。
API 原型:
// TUIConversationConfigClassic.java/*** Display unread count icon in each conversation cell.* The default value is true.*/public static void setShowCellUnreadCount(boolean showCellUnreadCount)
示例代码:
// When to call: Before initializing conversation list.TUIConversationConfigClassic.setShowCellUnreadCount(false);
设置效果:
不展示会话 cell 上的未读红点 | 默认 |
| |
展示在线状态
API 作用:展示 cell 里用户头像上的在线状态 icon。针对所有 cell 生效。
API 原型:
// TUIConversationConfigClassic.java/*** Display user's online status icon in conversation list.* The default value is false.*/public static void setShowUserOnlineStatusIcon(boolean showUserOnlineStatusIcon)
示例代码:
// When to call: Before initializing conversation list.TUIConversationConfigClassic.setShowUserOnlineStatusIcon(true);
设置效果:
展示在线状态 | 默认 |
| |
会话更多菜单选项自定义
API 作用:隐藏会话更多菜单选项、向会话更多菜单添加选项。针对指定会话生效。
API 原型:
// TUIConversationConfigClassic.javapublic interface ConversationMenuItemDataSource { /** * Implement this method to add new items. */ default List<PopMenuAction> conversationShouldAddNewItemsToMoreMenu(ConversationInfo conversationInfo) { return new ArrayList<>(); } /** * Implement this method to hide items in more menu. */ default @ConversationMenuItem List<Integer> conversationShouldHideItemsInMoreMenu(ConversationInfo conversationInfo) { return new ArrayList<>(); } }
示例代码:
// When to call: Before initializing conversation list.TUIConversationConfigClassic.setConversationMenuItemDataSource(new TUIConversationConfigClassic.ConversationMenuItemDataSource() { @Override public List<Integer> conversationShouldHideItemsInMoreMenu(ConversationInfo conversationInfo) { return Arrays.asList(TUIConversationConfigClassic.HIDE); } @Override public List<PopMenuAction> conversationShouldAddNewItemsToMoreMenu(ConversationInfo conversationInfo) { PopMenuAction item = new PopMenuAction(); item.setActionName("action1"); item.setIconResId(R.drawable.ic_launcher); item.setActionClickListener(new PopActionClickListener() { @Override public void onActionClick(int index, Object data) { ToastUtil.toastShortMessage("action1 clicked"); } }); return Arrays.asList(item); } });
设置效果:
添加选项 | 默认 |
| |