跳到主要内容

输入区域

Global IM UIKit 的输入区域是在 InputPanelComponent 统一创建和控制的,支持自定义输入模式、自定义扩展区域(插件)、以及自定义贴纸。

下图输入区从左至右依次是加号扩展按钮、内容输入框、贴纸按钮、语音录制按钮。

(width=250)

修改输入栏组合模式

输入框文本输入区域不允许修改,只支持对文本输入区域的左右按钮增加或者删除。

  1. 您可以通过重写 InputPanelComponent#beforeCreateLeftInputActionView(@NonNull List<InputAction> leftInputActions)方法 获取到默认的左边按钮并对其修改。

  2. 您可以通过重写 InputPanelComponent#beforeCreateRightInputActionView(@NonNull List<InputAction> rightInputActions) 方法 获取到默认的右边按钮并对其修改。

public class CustomInputPanelComponent extends InputPanelComponent{

@NonNull
@Override
protected List<InputAction> beforeCreateLeftInputActionView(@NonNull List<InputAction> leftInputActions) {
// 增加
leftInputActions.add(new InputAction() {
@Override
public Drawable obtainDrawable(@NonNull Context context) {
return ResourcesCompat.getDrawable(context.getResources(), com.rongcloud.im.uikit.R.drawable.rc_icon_voice, null);
}

@Override
public void onClick(@NonNull View view) {
Toast.makeText(getContext(), "voice Clicked", Toast.LENGTH_SHORT).show();
}
});
return super.beforeCreateLeftInputActionView(leftInputActions);
}


@NonNull
@Override
protected List<InputAction> beforeCreateRightInputActionView(@NonNull List<InputAction> rightInputActions) {
// 添加
rightInputActions.add(new InputAction() {
@Override
public Drawable obtainDrawable(@NonNull Context context) {
return ResourcesCompat.getDrawable(context.getResources(), com.rongcloud.im.uikit.R.drawable.rc_icon_camera, null);
}

@Override
public void onClick(@NonNull View view) {
Toast.makeText(getContext(), "camera Clicked", Toast.LENGTH_SHORT).show();
}
});
return super.beforeCreateRightInputActionView(rightInputActions);
}
}

输入区域扩展面板

融云将点击输入栏 + 号按钮时展示的面板称为扩展面板,扩展面板上可以实现相册、相机、文件等功能。

您可以通过操作 重写 InputPanelComponent#beforeCreateInputMoreActionView(@NonNull List<InputMoreAction> chatActions) 增加、删除、修改扩展功能。

public class CustomInputPanelComponent extends InputPanelComponent{

@NonNull
@Override
protected List<InputMoreAction> beforeCreateInputMoreActionView(@NonNull List<InputMoreAction> inputMoreActions) {
// 方式1. 移除文件按钮
Iterator<InputMoreAction> iterator = inputMoreActions.iterator();
while (iterator.hasNext()) {
InputMoreAction inputMoreAction = iterator.next();
if (inputMoreAction instanceof FileInputMoreAction) {
iterator.remove();
}
}

// 方式2. 添加自定义的 InputMoreAction
inputMoreActions.add(new InputMoreAction() {
@Override
public String obtainTitle(@NonNull Context context) {
return "Position";
}

@Override
public Drawable obtainDrawable(@NonNull Context context) {
return ResourcesCompat.getDrawable(context.getResources(), com.rongcloud.im.uikit.R.drawable.rc_icon_camera, null);
}

@Override
public void onClick(@NonNull View view) {
Toast.makeText(getContext(), "Position Clicked", Toast.LENGTH_SHORT).show();
}
});
return super.beforeCreateInputMoreActionView(inputMoreActions);
}

}

默认的菜单选项可以根据 class 来区分,参考如下:

功能class
相册AlbumInputMoreAction
拍照CameraInputMoreAction
文件FileInputMoreAction

贴纸面板

Global IM UIKit 默认只提供贴纸按钮(如下图)和贴纸展示的面板,贴纸资源需要由应用程序提供给 Global IM UIKit。

(width=250)

关于如何添加自定义贴纸,详见贴纸消息