logo
On this page

Add custom components to the call

Customize the foreground view

If you want to add some custom components at the top level of the view, such as, you want to display the user avatars when the video view is displayed, add user-level icons, etc., then you can use setForegroundViewProvider method. The setForegroundViewProvider requires you (the developer) to return a custom Widget that will be placed at the top of the view.

Here is the reference code:

// sample for custom Widget at the top of the view
public class YourCustomView extends ZegoBaseAudioVideoForegroundView {

    public YourCustomView(@NonNull Context context, String userID) {
        super(context, userID);
    }

    public YourCustomView(@NonNull Context context, @Nullable AttributeSet attrs,
        String userID) {
        super(context, attrs, userID);
    }

    protected void onForegroundViewCreated(ZegoUIKitUser uiKitUser) {
        // init your custom view
    }

    protected void onCameraStateChanged(boolean isCameraOn) {
        // will be called when camera changed
    }

    protected void onMicrophoneStateChanged(boolean isMicrophoneOn) {
        // will be called when microphone changed
    }

    protected void onInRoomAttributesUpdated(HashMap<String, String> inRoomAttributes) {
        // will be called when inRoomAttributes changed
    }
}

public class CallActivity extends AppCompatActivity {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_call);

    long appID = YourAppID;
    String appSign = YourAppSign;
    String userID = "userID";
    String userName = "userName";
    String callID = "testCallID";

    // Modify your custom configurations here.
    ZegoUIKitPrebuiltCallConfig config = ZegoUIKitPrebuiltCallConfig.oneOnOneVideoCall();
    config.audioVideoViewConfig.videoViewForegroundViewProvider = new ZegoForegroundViewProvider() {
        @Override
        public ZegoBaseAudioVideoForegroundView getForegroundView(ViewGroup parent, ZegoUIKitUser uiKitUser) {
            YourCustomView foregroundView = new YourCustomView(parent.getContext(),uiKitUser.userID);
            return foregroundView;
        }
    };

    ZegoUIKitPrebuiltCallFragment fragment = ZegoUIKitPrebuiltCallFragment.newInstance(appID, appSign, callID, userID, userName, config);
    getSupportFragmentManager()
            .beginTransaction()
            .replace(R.id.fragment_container, fragment)
            .commitNow();
  }
}

Customize the audio view

If you need to customize the user's view in audio mode, for example, setting the background image, you can use largeViewBackgroundImage, smallViewBackgroundImage, largeViewBackgroundColor, smallViewBackgroundColor in ZegoLayoutPictureInPictureConfig.

These configurations are only valid when the user turns off the camera (because the video view will be displayed automatically when the camera is on).

Here is the reference code:

public class CallActivity extends AppCompatActivity {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_call);

    long appID = YourAppID;
    String appSign = YourAppSign;
    String userID = "userID";
    String userName = "userName";
    String callID = "testCallID";

    // Modify your custom configurations here.
    ZegoUIKitPrebuiltCallConfig config = ZegoUIKitPrebuiltCallConfig.oneOnOneVideoCall();
    ZegoLayoutPictureInPictureConfig pipConfig =  new ZegoLayoutPictureInPictureConfig();
    pipConfig.smallViewBackgroundColor = Color.parseColor("#333437");
    pipConfig.largeViewBackgroundColor = Color.parseColor("#4A4B4D");
    config.layout.config = pipConfig;

    ZegoUIKitPrebuiltCallFragment fragment = ZegoUIKitPrebuiltCallFragment
            .newInstance(appID, appSign, callID, userID, userName, config);

    getSupportFragmentManager()
            .beginTransaction()
            .replace(R.id.fragment_container, fragment)
            .commitNow();
  }
}

Previous

Set avatar for users

Next

Configure layouts

On this page

Back to top