当前位置:主页 > 查看内容

即时通信 IM 快速搭建(Android) - SDK 文档

发布时间:2021-10-17 00:00| 位朋友查看

简介:常用的聊天软件都是由聊天窗口、会话列表等几个基本的界面组成。TUIKit 提供一套基本的 UI 实现,简化 IM SDK 的集成过程,只需几行代码即可在项目中使用 IM SDK 提供通信功能。 说明: 更多实操教学视频请参见:极速集成 TUIKit(Android)。 创建会话列表……

常用的聊天软件都是由聊天窗口、会话列表等几个基本的界面组成。TUIKit 提供一套基本的 UI 实现,简化 IM SDK 的集成过程,只需几行代码即可在项目中使用 IM SDK 提供通信功能。

说明:

更多实操教学视频请参见:极速集成 TUIKit(Android)。

创建会话列表界面

会话列表 ConversationLayout 继承自 LinearLayout,其数据的获取、同步、展示以及交互均已在 TUIKit 内部封装,会话列表 UI 的使用与 Android 的普通 View 一样方便。
会话列表

  1. 在任意 layout.xml 中设置布局:
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent">
       <com.tencent.qcloud.tim.uikit.modules.conversation.ConversationLayout
          android:id="@+id/conversation_layout"
          android:layout_width="match_parent"
          android:layout_height="match_parent" />
    </LinearLayout>
  2. 在代码中引用:
    // 从布局文件中获取会话列表面板
    ConversationLayout conversationLayout = findViewById(R.id.conversation_layout);
    // 初始化聊天面板
    conversationLayout.initDefault();

打开聊天界面

聊天界面

  1. 在任意 layout.xml 中设置布局:
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent">
       <com.tencent.qcloud.tim.uikit.modules.chat.ChatLayout
          android:id="@+id/chat_layout"
          android:layout_width="match_parent"
          android:layout_height="match_parent"/>
    </LinearLayout>
  2. 在代码中引用:
    // 从布局文件中获取聊天面板
    ChatLayout chatLayout = findViewById(R.id.chat_layout);
    // 单聊面板的默认 UI 和交互初始化
    chatLayout.initDefault();
    // 传入 ChatInfo 的实例,这个实例必须包含必要的聊天信息,一般从调用方传入
    // 构造 mChatInfo 可参考 StartC2CChatActivity.java 的方法 startConversation
    chatLayout.setChatInfo(mChatInfo);
    

添加通讯录界面

通讯录

  1. 在任意 layout.xml 中设置布局:
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <com.tencent.qcloud.tim.uikit.modules.contact.ContactLayout
      android:id="@+id/contact_layout"
      android:layout_width="match_parent"
      android:layout_height="match_parent" />
    </LinearLayout>
  2. 在代码中引用:
    // 从布局文件中获取通讯录面板
    ContactLayout contactLayout = findViewById(R.id.contact_layout);
    // 通讯录面板的默认 UI 和交互初始化
    contactLayout.initDefault();

本站部分内容转载于网络,版权归原作者所有,转载之目的在于传播更多优秀技术内容,如有侵权请联系QQ/微信:153890879删除,谢谢!

推荐图文

  • 周排行
  • 月排行
  • 总排行

随机推荐